TutRwMutexWriteLock write-lock a R/W mutex
rw_mutex
R/W mutex object to lock
TRUE
if lock was granted, FALSE
otherwise.
If TutRwMutexWriteLock fails, it returns FALSE
and sets the global SmartSockets error number to one of:
TutRwMutexWriteLock write-locks a R/W mutex. A write-lock implies that the thread may safely examine and modify the state of the resource protected by the R/W mutex. Write-locks exclude all other threads from accessing the resource. Because there is no mechanism for taking a lock away from a thread once it has been granted, TutRwMutexWriteLock may need to suspend the calling thread until all of the read-locks have been released. If new read-locks were granted during this time, the thread calling TutRwMutexWriteLock might wait indefinitely, never getting a chance to update the protected resource. For that reason, waiting writer-threads preempt new reader threads.
Like normal mutexes, R/W mutexes can be recursively locked. A thread is never suspended by a recursive lock operation. This means that a thread already granted a read-lock always succeeds immediately in obtaining another read-lock, and a thread already granted a write-lock succeeds immediately in obtaining either a read-lock or a write-lock.
If a reader-thread attempts to write-lock the R/W mutex, it automatically has its read-lock upgraded. This means the thread is suspended (if necessary) until all other reader-threads have released their locks, and then is granted a write-lock (upgrades preempt normal write-lock acquisitions and are FIFO with respect to other upgraders). The thread is then a writer-thread and remains a writer-thread until all of its locks have been released. It is possible to explicitly upgrade to a write-lock with TutRwMutexUpgradeLock.
Every call to TutRwMutexWriteLock should be balanced by a subsequent call to TutRwMutexUnlock.
TutRwMutexCreate, TutRwMutexReadLock, TutRwMutexUnlock, TutRwMutexUpgradeLock
This example write-locks a R/W mutex:
TIBCO SmartSockets™ Utilities Software Release 6.8, July 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |