Class creadwritesection <br/>{< br/> Public: <br/> creadwritesection () {<br/> initializecriticalsection (& _ csenterread ); <br/> initializecriticalsection (& _ cswriter); <br/> _ lreaders =-1; <br/>}< br/> ~ Creadwritesection () {<br/> deletecriticalsection (& _ csenterread); <br/> deletecriticalsection (& _ cswriter); <br/>}< br/> void enterread () <br/>{< br/> entercriticalsection (& _ csenterread); <br/> If (! Interlockedincrement (& _ lreaders) <br/> entercriticalsection (& _ cswriter); <br/> leavecriticalsection (& _ csenterread ); <br/>}< br/> void leaveread () <br/> {<br/> If (interlockeddecrement (& _ lreaders) <0) <br/> leavecriticalsection (& _ cswriter); <br/>}< br/> void enterwrite () <br/>{< br/> entercriticalsection (& _ csenterread ); <br/> entercriticalsection (& _ cswriter); <br/>}< br/> void leavewrite () <br/ >{< Br/> leavecriticalsection (& _ cswriter); <br/> leavecriticalsection (& _ csenterread ); <br/>}< br/> // note that readers will continue reading underneath this critical section <br/> critical_section * getpcs () <br/>{< br/> return & _ csenterread; <br/>}< br/> PRIVATE: <br/> critical_section _ csenterread; <br/> critical_section _ cswriter; <br/> long _ lreaders; <br/>}; <br/> class creadlock <br/> {<br /> Public: <br/> creadlock (creadwritesection & crws) {(_ prws = & crws)-> enterread () ;}< br/> ~ Creadlock () {_ prws-> leaveread () ;}< br/> PRIVATE: <br/> creadwritesection * _ prws; <br/> }; <br/> class cwritelock <br/> {<br/> Public: <br/> cwritelock (creadwritesection & crws) {(_ prws = & crws) -> enterwrite () ;}< br/> ~ Cwritelock () {_ prws-> leavewrite () ;}< br/> PRIVATE: <br/> creadwritesection * _ prws; <br/> }; <br/> # define lock_read (crws) creadlock crws # _ readlock (crws) <br/> # define lock_write (crws) cwritelock crws # _ writelock (crws)