Ignore:
Timestamp:
Feb 26, 2020, 6:13:54 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
04e6f93, 5452673, dac55004
Parents:
aeb5d0d (diff), 7dc2e015 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 moved

Legend:

Unmodified
Added
Removed
  • doc/papers/concurrency/examples/RWMonitorEXT.cfa

    raeb5d0d r930b504  
    77        int rcnt, wcnt;                                                                         // number of readers/writer using resource
    88};
     9
     10void ?{}( ReadersWriter & rw ) with(rw) { rcnt = wcnt = 0; }
    911void EndRead( ReadersWriter & mutex rw ) with(rw) { rcnt -= 1; }
    1012void EndWrite( ReadersWriter & mutex rw ) with(rw) { wcnt = 0; }
    1113void StartRead( ReadersWriter & mutex rw ) with(rw) {
    12         if ( wcnt > 0 ) waitfor( EndWrite, rw );
     14        if ( wcnt > 0 ) waitfor( EndWrite : rw );
    1315        rcnt += 1;
    1416}
    1517void 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 );
    1820        wcnt = 1;
    1921}
    20 void ?{}( ReadersWriter & rw ) with(rw) { rcnt = wcnt = 0; }
    2122int readers( ReadersWriter & rw ) { return rw.rcnt; }
     23
    2224void Read( ReadersWriter & rw ) {
    2325        StartRead( rw );
     
    3436        EndWrite( rw );
    3537}
     38
    3639thread Worker {
    3740        ReadersWriter &rw;
     
    4750        } // for
    4851}
     52
    4953int main() {
    5054        enum { MaxTask = 5 };
     
    5761} // main
    5862
    59 
    6063// Local Variables: //
    6164// tab-width: 4 //
    62 // compile-command: "cfa -O2 RWMonitor.cfa" //
     65// compile-command: "cfa -O2 RWMonitorEXT.cfa" //
    6366// End: //
Note: See TracChangeset for help on using the changeset viewer.