Changeset 237df76 for tests/io/io-acquire.cfa
- Timestamp:
- Oct 6, 2021, 8:40:19 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 05c941a, 68fe946e
- Parents:
- 8dcb832
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/io/io-acquire.cfa
r8dcb832 r237df76 10 10 // Created On : Mon Mar 1 18:40:09 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Apr 27 11:49:34202113 // Update Count : 1812 // Last Modified On : Wed Oct 6 18:04:58 2021 13 // Update Count : 72 14 14 // 15 15 16 16 #include <fstream.hfa> 17 17 #include <thread.hfa> 18 #include <mutex_stmt.hfa> 18 19 19 20 thread T {}; … … 21 22 // output from parallel threads should not be scrambled 22 23 23 for ( 100 ) { // localprotection24 sout | acquire| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;24 for ( 100 ) { // expression protection 25 mutex(sout) sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; 25 26 } 26 { // global protection (RAII) 27 osacquire acq = { sout }; 27 mutex( sout ) { // statement protection 28 28 for ( 100 ) { 29 29 sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; … … 31 31 } 32 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; 33 ofstream & h1( ofstream & os ) { // helper 34 mutex( os ) return os | 1 | 2 | 3 | 4; // unnecessary mutex 35 } 36 ofstream & h2( ofstream & os ) { // helper 37 mutex( os ) return os | 6 | 7 | 8 | 9; // unnecessary mutex 38 } 39 mutex( sout ) { // unnecessary mutex 40 for ( 100 ) { 41 mutex( sout ) { 42 sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; 43 sout | h1 | 5 | h2; // refactored code 44 } 45 } 38 46 } 39 47 } … … 42 50 43 51 int a, b, c, d, e, f, g, h, i; 44 for ( 100 ) { // localprotection45 sin | acquire| a | b | c | d | e | f | g | h | i;52 for ( 100 ) { // expression protection 53 mutex(sin) sin | a | b | c | d | e | f | g | h | i; 46 54 } 47 { // global protection (RAII) 48 isacquire acq = { sin }; 55 mutex( sin ) { // statement protection 49 56 for ( 100 ) { 50 57 sin | a | b | c | d | e | f | g | h | i; … … 52 59 } 53 60 { // 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; 61 ifstream & h1( ifstream & is ) { // helper 62 mutex( is ) return is | a | b | c | d; // unnecessary mutex 63 } 64 ifstream & h2( ifstream & is ) { // helper 65 mutex( is ) return is | f | g | h | i; // unnecessary mutex 66 } 67 mutex( sin ) { // unnecessary mutex 68 for ( 5 ) { 69 mutex( sin ) { 70 sin | a | b | c | d | e | f | g | h | i; 71 sin | h1 | e | h2; // refactored code 72 } 73 } 59 74 } 60 75 }
Note: See TracChangeset
for help on using the changeset viewer.