00001 /* Trivial test of critical sections. */ 00002 00003 /* { dg-require-effective-target sync_int_long } */ 00004 00005 #include <omp.h> 00006 #include <sys/time.h> 00007 #include <unistd.h> 00008 #include <assert.h> 00009 #include "libgomp_g.h" 00010 00011 00012 static volatile int test = -1; 00013 00014 static void function(void *dummy) 00015 { 00016 int iam = omp_get_thread_num (); 00017 int old; 00018 00019 GOMP_critical_start (); 00020 00021 old = __sync_lock_test_and_set (&test, iam); 00022 assert (old == -1); 00023 00024 usleep (10); 00025 test = -1; 00026 00027 GOMP_critical_end (); 00028 } 00029 00030 int main() 00031 { 00032 omp_set_dynamic (0); 00033 00034 GOMP_parallel_start (function, NULL, 3); 00035 function (NULL); 00036 GOMP_parallel_end (); 00037 00038 return 0; 00039 }