source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks-fortran/DRB119-nestlock-orig-yes.f95

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100755
File size: 1.6 KB
Line 
1!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
2!!! Copyright (c) 2017-20, Lawrence Livermore National Security, LLC
3!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details.
4!!!
5!!! SPDX-License-Identifier: (BSD-3-Clause)
6!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
7
8!A nested lock can be locked several times. It doesn't unlock until you have unset
9!it as many times as the number of calls to omp_set_nest_lock.
10!incr_b is called at line 53 and line 58. So, it needs a nest_lock enclosing line 35
11!Missing nest_lock will lead to race condition at line:35.
12!Data Race Pairs, p%b@35:5 and p%b@35:5.
13
14module DRB118
15 use OMP_LIB, ONLY: OMP_NEST_LOCK_KIND
16 type pair
17 integer a
18 integer b
19 integer (OMP_NEST_LOCK_KIND) lck
20 end type
21end module
22
23subroutine incr_a(p, a)
24 use DRB118
25 type(pair) :: p
26 integer a
27 p%a = p%a + 1
28end subroutine
29
30subroutine incr_b(p, b)
31 use omp_lib
32 use DRB118
33 type(pair) :: p
34 integer b
35 p%b = p%b + 1
36end subroutine
37
38program DRB118_nestlock_orig_no
39 use omp_lib
40 use DRB118
41 implicit none
42
43 integer :: a, b
44
45 type(pair) :: p
46 p%a = 0
47 p%b = 0
48 call omp_init_nest_lock(p%lck);
49
50 !$omp parallel sections
51 !$omp section
52 call omp_set_nest_lock(p%lck)
53 call incr_b(p, a)
54 call incr_a(p, b)
55 call omp_unset_nest_lock(p%lck)
56
57 !$omp section
58 call incr_b(p, b);
59
60 !$omp end parallel sections
61
62 call omp_destroy_nest_lock(p%lck)
63
64 print*,p%b
65
66end program
Note: See TracBrowser for help on using the repository browser.