public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Kwok Yeung <kcy@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-11] openmp: Notify team barrier of pending tasks in omp_fulfill_event Date: Mon, 17 May 2021 21:22:14 +0000 (GMT) [thread overview] Message-ID: <20210517212214.B6FF33857817@sourceware.org> (raw) https://gcc.gnu.org/g:a21ebe77c5b93e7cdcf2ad3e8ea159fa54708343 commit a21ebe77c5b93e7cdcf2ad3e8ea159fa54708343 Author: Kwok Cheung Yeung <kcy@codesourcery.com> Date: Fri May 14 09:59:11 2021 -0700 openmp: Notify team barrier of pending tasks in omp_fulfill_event The team barrier should be notified of any new tasks that become runnable as the result of a completing task, otherwise the barrier threads might not resume processing available tasks, resulting in a hang. 2021-05-17 Kwok Cheung Yeung <kcy@codesourcery.com> libgomp/ * task.c (omp_fulfill_event): Call gomp_team_barrier_set_task_pending if new tasks generated. * testsuite/libgomp.c-c++-common/task-detach-13.c: New. (cherry picked from commit ba886d0c488ebea2eb2df95c2069a3e207704dac) Diff: --- libgomp/ChangeLog.omp | 9 ++++ libgomp/task.c | 1 + .../libgomp.c-c++-common/task-detach-13.c | 59 ++++++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp index 028ddc24841..94bc2a48017 100644 --- a/libgomp/ChangeLog.omp +++ b/libgomp/ChangeLog.omp @@ -1,3 +1,12 @@ +2021-05-17 Kwok Cheung Yeung <kcy@codesourcery.com> + + Backport from mainline + 2021-05-17 Kwok Cheung Yeung <kcy@codesourcery.com> + + * task.c (omp_fulfill_event): Call gomp_team_barrier_set_task_pending + if new tasks generated. + * testsuite/libgomp.c-c++-common/task-detach-13.c: New. + 2021-05-17 Tobias Burnus <tobias@codesourcery.com> Backported from master: diff --git a/libgomp/task.c b/libgomp/task.c index 1c73c759a8d..feb4796a3ac 100644 --- a/libgomp/task.c +++ b/libgomp/task.c @@ -2460,6 +2460,7 @@ omp_fulfill_event (omp_event_handle_t event) if (new_tasks > 0) { /* Wake up threads to run new tasks. */ + gomp_team_barrier_set_task_pending (&team->barrier); do_wake = team->nthreads - team->task_running_count; if (do_wake > new_tasks) do_wake = new_tasks; diff --git a/libgomp/testsuite/libgomp.c-c++-common/task-detach-13.c b/libgomp/testsuite/libgomp.c-c++-common/task-detach-13.c new file mode 100644 index 00000000000..9622fd8251f --- /dev/null +++ b/libgomp/testsuite/libgomp.c-c++-common/task-detach-13.c @@ -0,0 +1,59 @@ +/* { dg-do run { target *-*-linux* *-*-gnu* *-*-freebsd* } } */ +/* { dg-timeout 10 } */ + +/* Test that omp_fulfill_event works when called from an external + non-OpenMP thread. */ + +#include <omp.h> +#include <unistd.h> +#include <pthread.h> +#include <stdio.h> + +int finished = 0; +int event_pending = 0; +omp_event_handle_t detach_event; + +void * +fulfill_thread (void *) +{ + while (!__atomic_load_n (&finished, __ATOMIC_RELAXED)) + { + if (__atomic_load_n (&event_pending, __ATOMIC_ACQUIRE)) + { + omp_fulfill_event (detach_event); + __atomic_store_n (&event_pending, 0, __ATOMIC_RELEASE); + } + + sleep(1); + } + + return 0; +} + +int +main (void) +{ + pthread_t thr; + int dep; + pthread_create (&thr, NULL, fulfill_thread, 0); + + #pragma omp parallel + #pragma omp single + { + omp_event_handle_t ev; + + #pragma omp task depend (out: dep) detach (ev) + { + detach_event = ev; + __atomic_store_n (&event_pending, 1, __ATOMIC_RELEASE); + } + + #pragma omp task depend (in: dep) + { + __atomic_store_n (&finished, 1, __ATOMIC_RELAXED); + } + } + + pthread_join (thr, 0); + return 0; +}
reply other threads:[~2021-05-17 21:22 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210517212214.B6FF33857817@sourceware.org \ --to=kcy@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).