Hello,
RWLock version 1.0
Authors: Amine Moulay Ramdane.
Description: A fast Multiple-Readers-Exclusive-Writer Lock.
A Read/Write Lock is a performance improvement over a standard mutex for cases where reads outnumber writes. with a Read/Write Lock multiple simultaneous read locks may be held, but write locks are exclusively held.
The exclusive writing lock ensures that race conditions do not occur, since if one client is writing to the data no other client may read or write. Also, the allowance for multiple simultaneous read locks decreases resource contention since multiple readers can safely use the shared data.
This increases performance over a standard mutex for the assumed usage pattern of frequent simultaneous reads and infrequent writes.
The following implementation of Read/Write Lock make new read locks wait if there is a writer waiting for a lock and this implementation is fair cause it processes the Readers and Writers in FIFO order so it's good for Realtime systems.
I have provided you with two implementations, one that uses spinlocks and one that uses my SemaCondvar synchronization object that consumes less CPU than the spinlock implementation.
I have looked at another lockfree Read/Write Lock implementation called TOmniMREW that you will find in the OmniThread library(at
http://otl.17slon.com/), but this implementation is not suited for Realtime systems cause it's not fair and it doesn't process the reader and writers in FIFO order as is doing my implementation, other than that TOmniMREW consumes mush more CPU than my Read/Write Lock that uses my SemaCondvar.
Please take a look a the test.pas Object Pascal demo inside the zipfile, compile and run it...
Language: FPC Pascal v2.2.0+ / Delphi 7+:
http://www.freepascal.org/Operating Systems: Windows, Mac OSX , Linux , Unix...
Required FPC switches: -O3 -Sd -dFPC -dFreePascal
-Sd for delphi mode....
Thank you,
Amine Moulay Ramdane.