mirror of
https://github.com/OpenMP/Examples.git
synced 2025-04-07 23:22:11 +01:00
27 lines
487 B
C
27 lines
487 B
C
/*
|
|
* @@name: taskyield.1c
|
|
* @@type: C
|
|
* @@compilable: yes
|
|
* @@linkable: no
|
|
* @@expect: success
|
|
*/
|
|
#include <omp.h>
|
|
|
|
void something_useful ( void );
|
|
void something_critical ( void );
|
|
void foo ( omp_lock_t * lock, int n )
|
|
{
|
|
int i;
|
|
|
|
for ( i = 0; i < n; i++ )
|
|
#pragma omp task
|
|
{
|
|
something_useful();
|
|
while ( !omp_test_lock(lock) ) {
|
|
#pragma omp taskyield
|
|
}
|
|
something_critical();
|
|
omp_unset_lock(lock);
|
|
}
|
|
}
|