testsuite/libgomp.c/single-1.c

Go to the documentation of this file.
00001 /* Trivial test of single.  */
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 int test;
00013 
00014 static void f_nocopy (void *dummy)
00015 {
00016   if (GOMP_single_start ())
00017     {
00018       int iam = omp_get_thread_num ();
00019       int old = __sync_lock_test_and_set (&test, iam);
00020       assert (old == -1);
00021     }
00022 }
00023 
00024 static void f_copy (void *dummy)
00025 {
00026   int *x = GOMP_single_copy_start ();
00027   if (x == NULL)
00028     {
00029       int iam = omp_get_thread_num ();
00030       int old = __sync_lock_test_and_set (&test, iam);
00031       assert (old == -1);
00032       GOMP_single_copy_end (&test);
00033     }
00034   else
00035     assert (x == &test);
00036 }
00037 
00038 int main()
00039 {
00040   omp_set_dynamic (0);
00041 
00042   test = -1;
00043   GOMP_parallel_start (f_nocopy, NULL, 3);
00044   f_nocopy (NULL);
00045   GOMP_parallel_end ();
00046 
00047   test = -1;
00048   GOMP_parallel_start (f_copy, NULL, 3);
00049   f_copy (NULL);
00050   GOMP_parallel_end ();
00051 
00052   return 0;
00053 }

Generated on Fri Apr 5 05:38:10 2013 for Libgomp by  doxygen 1.4.7