source: CIVL/examples/concurrency/barrier4.cvl

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 100644
File size: 876 bytes
RevLine 
[a777dc1]1/* Using the concurrency.cvh library's barrier inside atomic block.
2 * civl verify -inputB=4 barrier.cvl
3 */
4#include <concurrency.cvh>
5
6$input int B = 4; // upper bound on number of threads
7$input int N; // number of threads
8$assume(1<=N && N<=B);
9int counter = 0; // shared variable used to test barrier
10$scope root = $here;
11$gbarrier gbarrier;
12
13void run(int tid) {
14 $barrier barrier = $barrier_create(root, gbarrier, tid);
15
16 $atomic {
17 while ($true) {
18 $assert(counter == 0);
19 $barrier_call_yield(barrier);
20 counter++;
21 $barrier_call_yield(barrier);
22 $assert(counter == N);
23 $barrier_call_yield(barrier);
24 counter--;
25 $barrier_call_yield(barrier);
26 }
27 }
28 $barrier_destroy(barrier);
29}
30
31void main() {
32 gbarrier = $gbarrier_create(root, N);
33 $parfor(int i: 0 .. N-1)
34 run(i);
35 $gbarrier_destroy(gbarrier);
36}
Note: See TracBrowser for help on using the repository browser.