ReadersWritersLock in an unmanaged C++ program.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Folks, I have posted this message on a different newsgroup but I did not get
a single response. I take it that it must not have been the right forum.
Anyways.

I am seeking the solution to the classic ReadersWritesLock with a slight
twist in My unmanaged C++. I can not import "System" and "System.Threading"
namespaces.

I need to use some kind of lock (semaphore, Mutex, or any other
alternative), among threads to alow multiple threads to use the shared
resource.
The threads will have either the "Reader" role or the "Writer" role.
As long as a the thread is a "Reader", and no "Writer" thread is holding
the lock or
waiting on the lock the Reader thread can proceed.
Multiple "Readers" can access the resource while there is no Writer.
Once a Writer enters the queue for the Wirte access, no new Reader will be
allowed to get the lock and it will encounter a timeout reject return value.
However, every previously entered Reader is allowed to complete its
operations until all releases its lock.
When no more Reader is pending, the Writer starts its
operation at the end of which it and then releases the lock. At this time
new Readers will be successfull in aquiring the lock.
When the first Writer thread is pending or working, all subsequent Readers
and/or Writer threads shall get the timeout rejection.

I have looked into documents for Semaphore, Mutext and "Wait Operations" but
I am not sure the semaphore's count-down can help me implementing the
algorithm.

Any Ideas and suggestions is greatly appreciated.
 
MJS_Jeff said:
I am seeking the solution to the classic ReadersWritesLock with a slight
twist in My unmanaged C++. I can not import "System" and "System.Threading"
namespaces.

I need to use some kind of lock (semaphore, Mutex, or any other
alternative), among threads to alow multiple threads to use the shared
resource.

I found this while googling with <reader-writer c++ synchronization>:
http://www.frostbytes.com/~jimf/papers/c++sync/c++sync.html

Maybe "Fair-Share Readers/Writer Class" is what you need.
 
MJS_Jeff said:
Any Ideas and suggestions is greatly appreciated.

Take a look at "Programming Applications for Microsoft Windows" book by
Jeffrey Richter
Chapter "Thread Synchronization Toolkit"

Vladimir.
 
Back
Top