Changeset 58fe85a for doc/papers/concurrency/examples/RWMonitorEXT.cfa
- Timestamp:
- Jan 7, 2021, 3:27:00 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- 2b4daf2, 64aeca0
- Parents:
- 3c64c668 (diff), eef8dfb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 moved
-
doc/papers/concurrency/examples/RWMonitorEXT.cfa (moved) (moved from doc/papers/concurrency/examples/RWMonitor.cfa ) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/concurrency/examples/RWMonitorEXT.cfa
r3c64c668 r58fe85a 7 7 int rcnt, wcnt; // number of readers/writer using resource 8 8 }; 9 10 void ?{}( ReadersWriter & rw ) with(rw) { rcnt = wcnt = 0; } 9 11 void EndRead( ReadersWriter & mutex rw ) with(rw) { rcnt -= 1; } 10 12 void EndWrite( ReadersWriter & mutex rw ) with(rw) { wcnt = 0; } 11 13 void StartRead( ReadersWriter & mutex rw ) with(rw) { 12 if ( wcnt > 0 ) waitfor( EndWrite ,rw );14 if ( wcnt > 0 ) waitfor( EndWrite : rw ); 13 15 rcnt += 1; 14 16 } 15 17 void StartWrite( ReadersWriter & mutex rw ) with(rw) { 16 if ( wcnt > 0 ) waitfor( EndWrite ,rw );17 else while ( rcnt > 0 ) waitfor( EndRead ,rw );18 if ( wcnt > 0 ) waitfor( EndWrite : rw ); 19 else while ( rcnt > 0 ) waitfor( EndRead : rw ); 18 20 wcnt = 1; 19 21 } 20 void ?{}( ReadersWriter & rw ) with(rw) { rcnt = wcnt = 0; }21 22 int readers( ReadersWriter & rw ) { return rw.rcnt; } 23 22 24 void Read( ReadersWriter & rw ) { 23 25 StartRead( rw ); … … 34 36 EndWrite( rw ); 35 37 } 38 36 39 thread Worker { 37 40 ReadersWriter &rw; … … 47 50 } // for 48 51 } 52 49 53 int main() { 50 54 enum { MaxTask = 5 }; … … 57 61 } // main 58 62 59 60 63 // Local Variables: // 61 64 // tab-width: 4 // 62 // compile-command: "cfa -O2 RWMonitor .cfa" //65 // compile-command: "cfa -O2 RWMonitorEXT.cfa" // 63 66 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.