[RISCV] Change func to funct in RISCVInstrInfoXqci.td. NFC (#119669)
[llvm-project.git] / openmp / runtime / test / lock / omp_init_lock.c
blob49fd6337a9da826055c4cd194eedb25983550745
1 // RUN: %libomp-compile-and-run
2 #include "omp_testsuite.h"
3 #include <stdio.h>
5 // This should be slightly less than KMP_I_LOCK_CHUNK, which is 1024
6 #define LOCKS_PER_ITER 1000
7 #define ITERATIONS (REPETITIONS + 1)
9 // This tests concurrently using locks on one thread while initializing new
10 // ones on another thread. This exercises the global lock pool.
11 int test_omp_init_lock() {
12 int i;
13 omp_lock_t lcks[ITERATIONS * LOCKS_PER_ITER];
14 #pragma omp parallel for schedule(static) num_threads(NUM_TASKS)
15 for (i = 0; i < ITERATIONS; i++) {
16 int j;
17 omp_lock_t *my_lcks = &lcks[i * LOCKS_PER_ITER];
18 for (j = 0; j < LOCKS_PER_ITER; j++) {
19 omp_init_lock(&my_lcks[j]);
21 for (j = 0; j < LOCKS_PER_ITER * 100; j++) {
22 omp_set_lock(&my_lcks[j % LOCKS_PER_ITER]);
23 omp_unset_lock(&my_lcks[j % LOCKS_PER_ITER]);
26 // Wait until all repetitions are done. The test is exercising growth of
27 // the global lock pool, which does not shrink when no locks are allocated.
29 int j;
30 for (j = 0; j < ITERATIONS * LOCKS_PER_ITER; j++) {
31 omp_destroy_lock(&lcks[j]);
35 return 0;
38 int main() {
39 // No use repeating this test, since it's exercising a private global pool
40 // which is not reset between test iterations.
41 return test_omp_init_lock();