| 1 |
/* { dg-do run { target *-*-linux* *-*-gnu* *-*-freebsd* } } */ |
| 2 |
/* { dg-timeout 10 } */ |
| 3 |
|
| 4 |
/* Test that omp_fulfill_event works when called from an external |
| 5 |
non-OpenMP thread. */ |
| 6 |
|
| 7 |
#include <omp.h> |
| 8 |
#include <unistd.h> |
| 9 |
#include <pthread.h> |
| 10 |
#include <stdio.h> |
| 11 |
|
| 12 |
int finished = 0; |
| 13 |
int event_pending = 0; |
| 14 |
omp_event_handle_t detach_event; |
| 15 |
|
| 16 |
void * |
| 17 |
fulfill_thread (void *) |
| 18 |
{ |
| 19 |
while (!__atomic_load_n (&finished, __ATOMIC_RELAXED)) |
| 20 |
{ |
| 21 |
if (__atomic_load_n (&event_pending, __ATOMIC_ACQUIRE)) |
| 22 |
{ |
| 23 |
omp_fulfill_event (detach_event); |
| 24 |
__atomic_store_n (&event_pending, 0, __ATOMIC_RELEASE); |
| 25 |
} |
| 26 |
|
| 27 |
sleep(1); |
| 28 |
} |
| 29 |
|
| 30 |
return 0; |
| 31 |
} |
| 32 |
|
| 33 |
int |
| 34 |
main (void) |
| 35 |
{ |
| 36 |
pthread_t thr; |
| 37 |
int dep; |
| 38 |
pthread_create (&thr, NULL, fulfill_thread, 0); |
| 39 |
|
| 40 |
#pragma omp parallel |
| 41 |
#pragma omp single |
| 42 |
{ |
| 43 |
omp_event_handle_t ev; |
| 44 |
|
| 45 |
#pragma omp task depend (out: dep) detach (ev) |
| 46 |
{ |
| 47 |
detach_event = ev; |
| 48 |
__atomic_store_n (&event_pending, 1, __ATOMIC_RELEASE); |
| 49 |
} |
| 50 |
|
| 51 |
#pragma omp task depend (in: dep) |
| 52 |
{ |
| 53 |
__atomic_store_n (&finished, 1, __ATOMIC_RELAXED); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
pthread_join (thr, 0); |
| 58 |
return 0; |
| 59 |
} |