Inheritance diagram for phRWLock:
The phRWLock reader-writer lock class is a complete recusive lock system through any path that starts with the write lock being obtained. Should the read lock be the first lock obtained, then only read locks can be recursively obtained. Should a write lock be required and one attempts to obtain a write lock when the first lock is a read lock, then a dead lock will occur. However, if the write lock is obtained first, any combination of read and write locks may be performed. Remember that each lock obtained in a recursive lock system requires the same number of unlock calls.
Because of certain multiple inheritence issues in C++, the phRWLock class derives from phObject. Any class (phLiveObject) that wishes to implement a reader-writer lock through public methods needs to wrap all the reader-writer methods within that object and create a private instance to a phRWLock object. Since most Phission objects also inherit from phMutex, the unlock call conflicts with the phMutex::unlock call. For this reason, the reader-writer unlock is wrapped using the “rwUnlock” method to provide a distinction between the two. The phMutex lock/unlocks are used for protecting the object in these classes whereas the phRWLock lock/unlocks are used to provide concurrent reader access to data values while providing serial access to writers.
A potential area for problems is a continuous spinning on the reader-writer class methods that acquire and release the reader locked critical sections or writer locked critical sections. Since the algorithm for acquisition of the reader lock includes checking whether some reader already has the lock and just incrementing a value, there is potential to completely shut out a writer. It is not explicitly stated whether there is First In First Out / Queue functionality to track the order in which readers or writers try to lock. Reader-writer locks should be paired with a semaphore that can signal new information instead of looping on the locking methods for the reader-writer lock.
http://cactus.eas.asu.edu/partha/Teaching/531.2004/Readers-Writers.htm http://www.cs.sonoma.edu/~kooshesh/cs450/ReaderWriter.html http://www.cis.temple.edu/~ingargio/old/cis307s95/readings/readwriters.html
I didn't use the above resources because I found the one below.
For WIN32, I used this reference: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndllpro/html/msdn_locktest.asp
Definition at line 188 of file phRWLock.h.
Public Member Functions
Private Member Functions
|Copyright (C) 2002 - 2007||
Philip D.S. Thoren ( firstname.lastname@example.org )
University Of Massachusetts at Lowell