IlsRWLock
 
IlsRWLock
Category 
Thread utility class - API FOR ADVANCED USERS
Inheritance Path 
IlsMTBase
IlsRWLock
Description 
A readers/writer lock is used to allow concurrent access to readers and unique access to writers. Certain error conditions are detected and flagged, such as an attempt to take a read lock when the thread already has a write lock, and vice versa. In these cases, the lock member functions return IlsFalse. The scheduling is done so that writers have priority. Hence, if a reader is running, new readers will be allowed just until a writer is blocked. Once a writer is waiting, all new readers will block until there are no more waiting writers. It is possible to provide the pointer to the mutex to use to protect the readers/writer lock. For details, see IlsCond.
Libraries 
<server> and <mvcomp>
Header File 
#include <ilsserver/ilthread.h>
Synopsis 
class IlsRWLock : public IlsMTbase
{
public:
IlsRWLock(IlsUnsafeMutex* = 0);
virtual ~IlsRWLock();
 
IlsBoolean rdlock();
IlsBoolean wrlock();
IlsBoolean unlock();
 
friend ostream& operator<<(ostream&, const IlsRWLock&);
};
Constructor 
IlsRWLock(IlsUnsafeMutex* = 0);
If a mutex is passed to the constructor, then it is the responsibility of the application to lock the mutex before accessing member functions.
Destructor 
virtual ~IlsRWLock();
Member Functions 
IlsBoolean rdlock();
This member function blocks until the thread acquires a read lock. It returns IlsFalse if an error occurs or if the thread already has a write lock.
IlsBoolean wrlock();
This member function blocks until the thread acquires a write lock. It returns IlsFalse if an error occurs or if the thread already has a read lock.
IlsBoolean unlock();
This member function unlocks the lock that was previously taken by the thread. It returns IlsFalse if an error occurs or if the thread did not have a lock. rdlock/wrlock and unlock can be nested but the other threads are unblocked only when the last unlock is performed.
Operators 
friend ostream& operator<<(ostream&, const IlsRWLock&);
This operator prints the name of the object to the output stream.
See Also 
IlsCond, IlsRWLocker, IlsThread, IlsUnsafeMutex

Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.