OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [libgomp/] [testsuite/] [libgomp.c/] [appendix-a/] [a.39.1.c] - Blame information for rev 320

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 273 jeremybenn
/* { dg-do run } */
2
 
3
#include <stdio.h>
4
#include <omp.h>
5
void
6
skip (int i)
7
{
8
}
9
 
10
void
11
work (int i)
12
{
13
}
14
int
15
main ()
16
{
17
  omp_lock_t lck;
18
  int id;
19
  omp_init_lock (&lck);
20
#pragma omp parallel shared(lck) private(id)
21
  {
22
    id = omp_get_thread_num ();
23
    omp_set_lock (&lck);
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))
28
      {
29
        skip (id);              /* we do not yet have the lock,
30
                                   so we must do something else */
31
      }
32
    work (id);                  /* we now have the lock
33
                                   and can do the work */
34
    omp_unset_lock (&lck);
35
  }
36
  omp_destroy_lock (&lck);
37
  return 0;
38
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.