20 #pragma omp parallel shared(lck) private(id)
22 id
= omp_get_thread_num ();
24 /* only one thread at a time can execute this printf */
25 printf ("My thread id is %d.\n", id
);
26 omp_unset_lock (&lck
);
27 while (!omp_test_lock (&lck
))
29 skip (id
); /* we do not yet have the lock,
30 so we must do something else */
32 work (id
); /* we now have the lock
33 and can do the work */
34 omp_unset_lock (&lck
);
36 omp_destroy_lock (&lck
);