Changeset 237df76
- 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
- Location:
- tests
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrent/semaphore.cfa
r8dcb832 r237df76 2 2 #include <locks.hfa> 3 3 #include <thread.hfa> 4 #include <mutex_stmt.hfa> 4 5 5 6 enum { num_blockers = 17, num_unblockers = 13 }; … … 28 29 thrash(); 29 30 P(ben); 30 if(((thread&)this).seqable.next != 0p) sout | acquire |"Link not invalidated";31 if(((thread&)this).seqable.next != 0p) mutex(sout) sout | "Link not invalidated"; 31 32 thrash(); 32 33 } -
tests/concurrent/sleep.cfa
r8dcb832 r237df76 1 1 #include <fstream.hfa> 2 2 #include <thread.hfa> 3 #include <mutex_stmt.hfa> 3 4 #include <time.hfa> 4 5 … … 29 30 30 31 int main() { 31 sout | acquire| "start";32 mutex( sout ) sout | "start"; 32 33 { 33 34 slow_sleeper slow; … … 36 37 yield(); 37 38 } 38 sout | acquire| "done";39 mutex( sout ) sout | "done"; 39 40 } 40 41 -
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 } -
tests/linking/io-acquire.cfa
r8dcb832 r237df76 17 17 #include <fstream.hfa> 18 18 #include <stdlib.hfa> 19 #include <mutex_stmt.hfa> 19 20 20 21 int main() { 21 22 int i; 22 23 if(threading_enabled()) { 23 stdout | acquire| "YES";24 mutex( stdout ) stdout | "YES"; 24 25 stdin | i; 25 26 } else { 26 stdout | acquire| "NO";27 mutex( stdout ) stdout | "NO"; 27 28 stdin | i; 28 29 }
Note: See TracChangeset
for help on using the changeset viewer.