Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="https://stackoverflow.com/a/909591/133516"><code>TOmniMREW</code></a> from <code>OmniThreadLibrary</code> claims to be faster and more lightweight: </p> <p>OTL is an excellent threading lib, BTW.</p> <h1>Sample Code</h1> <pre><code>TOmniReaderWriterLock = class(TInterfacedObject, IReaderWriterLock) private omrewReference: Integer; public { IReaderWriterLock } procedure BeginRead; procedure EndRead; procedure BeginWrite; procedure EndWrite; end; { TOmniReaderWriterLock } procedure TOmniReaderWriterLock.BeginRead; var currentReference: Integer; begin //Wait on writer to reset write flag so Reference.Bit0 must be 0 than increase Reference repeat currentReference := Integer(omrewReference) and not 1; until currentReference = Integer(InterlockedCompareExchange(Pointer(omrewReference), Pointer(Integer(currentReference) + 2), Pointer(currentReference))); end; procedure TOmniReaderWriterLock.EndRead; begin //Decrease omrewReference InterlockedExchangeAdd(@omrewReference, -2); end; procedure TOmniReaderWriterLock.BeginWrite; var currentReference: integer; begin //Wait on writer to reset write flag so omrewReference.Bit0 must be 0 then set omrewReference.Bit0 repeat currentReference := omrewReference and (not 1); until currentReference = Integer(InterlockedCompareExchange(Pointer(omrewReference), Pointer(currentReference+1), Pointer(currentReference))); //Now wait on all readers repeat until omrewReference = 1; end; procedure TOmniReaderWriterLock.EndWrite; begin omrewReference := 0; end; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload