[fpc-devel] new TMultiReadExclusiveWriteSynchronizer

Jonas Maebe jonas.maebe at elis.ugent.be
Fri Aug 28 14:55:02 CEST 2009

On 28 Aug 2009, at 14:43, 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.

It would make things worse on some platforms, because with very low  
sleep times you don't even get a context switch on Mac OS X (the  
routine just spins in user space for a short while).

> Any suggestions?

Add a flag that indicates that someone is interested in writing, block  
it on an rtlevent, and then
a) block new readers on some kind of barrier
b) when all current readers are finished, send the event to wake up  
the writer
c) when the writer is finished, wake up the readers by upping the  
d) if other writers arrived in the mean time, they'll contend with the  
readers over the critical section

Of course, there is at least one small problem with the above  
scenario, and that is that the thread manager does not implement  
semaphores on all platforms (wich would be quite helpful to implement  
the barrier).

I'd suggest to implement it in a platform-dependent way and use the  
primitives offered by the standard libraries of every platform. It's  
not like this causes an extra dependency, so why re-implement (and  
debug) the whole thing in a generic and probably sub-optimal way?


More information about the fpc-devel mailing list