Merge from mainline
[official-gcc.git] / libgomp / testsuite / libgomp.c / barrier-1.c
blob915f2dea97cc174a70d117402e180758c59793ba
1 /* Trivial test of barrier. */
3 #include <omp.h>
4 #include <sys/time.h>
5 #include <unistd.h>
6 #include <assert.h>
7 #include "libgomp_g.h"
10 struct timeval stamps[3][3];
12 static void function(void *dummy)
14 int iam = omp_get_thread_num ();
16 gettimeofday (&stamps[iam][0], NULL);
17 if (iam == 0)
18 usleep (10);
20 GOMP_barrier ();
22 if (iam == 0)
24 gettimeofday (&stamps[0][1], NULL);
25 usleep (10);
28 GOMP_barrier ();
30 gettimeofday (&stamps[iam][2], NULL);
33 int main()
35 omp_set_dynamic (0);
37 GOMP_parallel_start (function, NULL, 3);
38 function (NULL);
39 GOMP_parallel_end ();
41 assert (timercmp (&stamps[0][0], &stamps[0][1], <));
42 assert (timercmp (&stamps[1][0], &stamps[0][1], <));
43 assert (timercmp (&stamps[2][0], &stamps[0][1], <));
45 assert (timercmp (&stamps[0][1], &stamps[0][2], <));
46 assert (timercmp (&stamps[0][1], &stamps[1][2], <));
47 assert (timercmp (&stamps[0][1], &stamps[2][2], <));
49 return 0;