[10dafa4] | 1 | //
|
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
|
---|
| 3 | //
|
---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
---|
| 5 | // file "LICENCE" distributed with Cforall.
|
---|
| 6 | //
|
---|
| 7 | // io-acquire.cfa --
|
---|
| 8 | //
|
---|
| 9 | // Author : Peter A. Buhr
|
---|
| 10 | // Created On : Mon Mar 1 18:40:09 2021
|
---|
| 11 | // Last Modified By : Peter A. Buhr
|
---|
[cbedb611] | 12 | // Last Modified On : Tue Apr 27 11:49:34 2021
|
---|
| 13 | // Update Count : 18
|
---|
[10dafa4] | 14 | //
|
---|
| 15 |
|
---|
| 16 | #include <fstream.hfa>
|
---|
| 17 | #include <thread.hfa>
|
---|
| 18 |
|
---|
| 19 | thread T {};
|
---|
| 20 | void main( T & ) {
|
---|
| 21 | // output from parallel threads should not be scrambled
|
---|
| 22 |
|
---|
| 23 | for ( 100 ) { // local protection
|
---|
| 24 | sout | acquire | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
---|
| 25 | }
|
---|
| 26 | { // global protection (RAII)
|
---|
| 27 | osacquire acq = { sout };
|
---|
| 28 | for ( 100 ) {
|
---|
| 29 | sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 | { // duplicate protection demonstrating recursive lock
|
---|
| 33 | osacquire acq = { sout };
|
---|
| 34 | for ( 100 ) {
|
---|
| 35 | osacquire acq = { sout };
|
---|
| 36 | sout | acquire | 1 | 2 | 3 | 4 | 5 | acquire | 6 | 7 | 8 | 9;
|
---|
| 37 | sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | // above output used as input to parallel threads
|
---|
| 42 |
|
---|
| 43 | int a, b, c, d, e, f, g, h, i;
|
---|
| 44 | for ( 100 ) { // local protection
|
---|
[cbedb611] | 45 | sin | acquire | a | b | c | d | e | f | g | h | i;
|
---|
[10dafa4] | 46 | }
|
---|
| 47 | { // global protection (RAII)
|
---|
| 48 | isacquire acq = { sin };
|
---|
| 49 | for ( 100 ) {
|
---|
| 50 | sin | a | b | c | d | e | f | g | h | i;
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 | { // duplicate protection demonstrating recursive lock
|
---|
| 54 | isacquire acq = { sin };
|
---|
| 55 | for ( 100 ) {
|
---|
| 56 | isacquire acq = { sin };
|
---|
| 57 | sin | acquire | a | b | c | d | e | acquire | f | g | h | i;
|
---|
| 58 | sin | a | b | c | d | e | f | g | h | i;
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | int main() {
|
---|
| 63 | processor p;
|
---|
| 64 | T t[5];
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | // Local Variables: //
|
---|
| 68 | // tab-width: 4 //
|
---|
| 69 | // compile-command: "cfa io-acquire.cfa" //
|
---|
| 70 | // End: //
|
---|