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:
790 bytes
|
| Rev | Line | |
|---|
| [48bfab9] | 1 | /**
|
|---|
| 2 | * This example demonstrates the features of CIVL's system function for implementing barriers.
|
|---|
| 3 | */
|
|---|
| 4 |
|
|---|
| [4208097] | 5 | #include<civlc.cvh>
|
|---|
| 6 | #include<concurrency.cvh>
|
|---|
| [48bfab9] | 7 |
|
|---|
| 8 | $input int N;
|
|---|
| [0baeebd] | 9 | $input int B = 5;
|
|---|
| [3ff27cf] | 10 | $assume(N > 0 && N < B);
|
|---|
| [48bfab9] | 11 | $gbarrier gbarrier = $gbarrier_create($here, N);
|
|---|
| 12 | int counter = 0;
|
|---|
| 13 |
|
|---|
| 14 | void process(int id) {
|
|---|
| 15 | $barrier barrier = $barrier_create($here, gbarrier, id);
|
|---|
| 16 |
|
|---|
| 17 | while($true){
|
|---|
| [d980649] | 18 | $assert(counter == 0);
|
|---|
| [48bfab9] | 19 | $barrier_call(barrier);
|
|---|
| 20 | counter++;
|
|---|
| 21 | $barrier_call(barrier);
|
|---|
| [d980649] | 22 | $assert(counter == N);
|
|---|
| [48bfab9] | 23 | $barrier_call(barrier);
|
|---|
| 24 | counter--;
|
|---|
| 25 | $barrier_call(barrier);
|
|---|
| 26 | }
|
|---|
| 27 | $barrier_destroy(barrier);
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | void main(){
|
|---|
| 31 | $proc procs[N];
|
|---|
| 32 |
|
|---|
| 33 | for(int i = 0; i < N; i++)
|
|---|
| 34 | procs[i] = $spawn process(i);
|
|---|
| 35 | for(int i = 0; i < N; i++)
|
|---|
| 36 | $wait(procs[i]);
|
|---|
| 37 | $gbarrier_destroy(gbarrier);
|
|---|
| 38 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.