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:
804 bytes
|
| Rev | Line | |
|---|
| [a777dc1] | 1 | /* Using the concurrency.cvh library's barrier. Usage:
|
|---|
| 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);
|
|---|
| 9 | int counter = 0; // shared variable used to test barrier
|
|---|
| 10 | $scope root = $here;
|
|---|
| 11 | $gbarrier gbarrier;
|
|---|
| 12 |
|
|---|
| 13 | void run(int tid) {
|
|---|
| 14 | $barrier barrier = $barrier_create(root, gbarrier, tid);
|
|---|
| 15 |
|
|---|
| 16 | while ($true) {
|
|---|
| 17 | $assert(counter == 0);
|
|---|
| 18 | $barrier_call(barrier);
|
|---|
| 19 | counter++;
|
|---|
| 20 | $barrier_call(barrier);
|
|---|
| 21 | $assert(counter == N);
|
|---|
| 22 | $barrier_call(barrier);
|
|---|
| 23 | counter--;
|
|---|
| 24 | $barrier_call(barrier);
|
|---|
| 25 | }
|
|---|
| 26 | $barrier_destroy(barrier);
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | void main() {
|
|---|
| 30 | gbarrier = $gbarrier_create(root, N);
|
|---|
| 31 | $parfor(int i: 0 .. N-1)
|
|---|
| 32 | run(i);
|
|---|
| 33 | $gbarrier_destroy(gbarrier);
|
|---|
| 34 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.