Recent

Author Topic: RWLock version 1.0  (Read 3284 times)

aminer

  • Hero Member
  • *****
  • Posts: 956
RWLock version 1.0
« on: June 17, 2013, 02:16:55 am »

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.


aminer

  • Hero Member
  • *****
  • Posts: 956
Re: RWLock version 1.0
« Reply #1 on: June 17, 2013, 02:18:20 am »

Hello,

You can download RWLock version 1.0 from:

http://pages.videotron.com/aminer/


Thank you,
Amine Moulay Ramdane.


aminer

  • Hero Member
  • *****
  • Posts: 956
Re: RWLock version 1.0
« Reply #2 on: June 17, 2013, 03:52:31 am »
Hello,

About my SemaCondvar sychronization object, i think i have
another idea, i must enhance it to support  queueing in prioritised FIFO order (a POSIX requirement for realtime etc),
so in my next version of SemaCondvar you will be able to 
timed wait with a priority ,you will have three priorities
LOW_PRIORITY,NORMAL_PRIORITY and HIGH_PRIORITY.
so you will be able to call wait() like this: wait(INIFINITE,HIGH_PRIORITY), this will be interresting.
where you will be using this ? fo example my new RWLock
that uses my SemaCondvar will be able to prioritize the the Writers
or the Readers or give them both the same priority.

So you will be able to call the my RWLock constructor
with the following parameters mpReaders, mpWriters, mpEqual
mpReaders means: MREW preferred Readers (with this my RWLock  will give higher priority to the readers).
mpReaders means: MREW preferred Writers (with this my RWLock  will give higher priority to the writers).
and mpEqual means: MREW preferred equal. (with this my RWLock  will give equal priority to the writers and to the readers).

So my next implementation of SemaCondvar will support priorities.

I have also another new idea , i will enhance my SemaCondvar to support
something new, if for example you don't want my SemaCondvar to signal all the waiters until a number of signals are reached , this will be interresting if you want for example to wait efficiently on a number of threads etc. like the WaitForMultipleObjects of windows, i think the Semaphore and the Conditional variable don't support this, but my SemaCondvar will support this.




Thank you,
Amine Moulay Ramdane.



 

TinyPortal © 2005-2018