[fpc-devel] new TMultiReadExclusiveWriteSynchronizer

Martin fpc at mfriebe.de
Fri Aug 28 15:29:33 CEST 2009

Is there support for semaphores?
the following should work

you need:
- a WriterSemaphore initialized at 1
  (the writer semaphore is like the CriticalSection, it may be better 
named ExclusiveSemaphore)
- a ReaderSemaphore initalized at 0

* when writing you will do this
- decrease the WriterSemaphore  by 1
  if a writer already exists (writing or waiting for readers to finish) 
then it already is zero, and the code will wait
- wait for the ReaderSemaphore  to be 0
- increase the WriterSemaphore  by 1

* when reading you will do this
- decrease the WriterSemaphore  by 1
  we cannot start if a writer is active
- increase the ReaderSemaphore  by 1
  this will prevent writers
- increase the WriterSemaphore  by 1
  (so other readers can enter read)
- decrease the ReaderSemaphore  by 1

Graeme Geldenhuys wrote:
> Graeme Geldenhuys wrote:
>> As I mentioned in the fpc-pascal mailing list. The current
>> implementation is wrong and is actually the equivalent of Delphi's
>> TSimpleRWSync class.
> Regarding Florian's comment in the bug tracker. I was using Sleep(100)
> which Florian says will slow down the class a lot.
> Has anybody got a better solution to this? I guess dropping the Sleep
> time even lower might not be the best solution either. Any suggestions?
> Regards,
>   - Graeme -

More information about the fpc-devel mailing list