| 1 |
/* Trivial test of critical sections. */ |
| 2 |
|
| 3 |
/* { dg-require-effective-target sync_int_long } */ |
| 4 |
|
| 5 |
#include <omp.h> |
| 6 |
#include <sys/time.h> |
| 7 |
#include <unistd.h> |
| 8 |
#include <assert.h> |
| 9 |
#include "libgomp_g.h" |
| 10 |
|
| 11 |
|
| 12 |
static volatile int test = -1; |
| 13 |
|
| 14 |
static void function(void *dummy) |
| 15 |
{ |
| 16 |
int iam = omp_get_thread_num (); |
| 17 |
int old; |
| 18 |
|
| 19 |
GOMP_critical_start (); |
| 20 |
|
| 21 |
old = __sync_lock_test_and_set (&test, iam); |
| 22 |
assert (old == -1); |
| 23 |
|
| 24 |
usleep (10); |
| 25 |
test = -1; |
| 26 |
|
| 27 |
GOMP_critical_end (); |
| 28 |
} |
| 29 |
|
| 30 |
int main() |
| 31 |
{ |
| 32 |
omp_set_dynamic (0); |
| 33 |
|
| 34 |
GOMP_parallel_start (function, NULL, 3); |
| 35 |
function (NULL); |
| 36 |
GOMP_parallel_end (); |
| 37 |
|
| 38 |
return 0; |
| 39 |
} |