thread rwmutex
Makes and locks the read and write mutexes of the group.
thread::rwmutex create
thread::rwmutex rlock MUTEX
thread::rwmutex wlock MUTEX
thread::rwmutex unlock MUTEX
thread::rwmutex destroy MUTEX
Description
The command thread::rwmutex works on mutexes with two kinds of lock. create makes one and gives its handle, such as wid0. rlock gets a read lock, which many threads can hold at one time, and which a thread can get more than once. wlock gets the write lock, which one thread holds with no reader. unlock releases one lock, and destroy removes the mutex.
A thread that holds a read lock or the write lock and asks for the write lock gets an error. The waits work as for thread::mutex.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| MUTEX | mutex handle | required | A handle of thread::rwmutex create. |
Returns
The handle for create, else an empty string.
Examples
% thread::rwmutex create
wid0
% set w [thread::rwmutex create]
> thread::rwmutex rlock $w
> thread::rwmutex rlock $w
> thread::rwmutex unlock $w
> thread::rwmutex unlock $w
% set w [thread::rwmutex create]
> thread::rwmutex wlock $w
> thread::rwmutex unlock $w
> thread::rwmutex destroy $w
Errors
% thread::rwmutex
wrong # args: should be "thread::rwmutex option ?args?"
-errorcode TCL WRONGARGS
% thread::rwmutex rlock
wrong # args: should be "thread::rwmutex rlock mutexHandle"
-errorcode TCL WRONGARGS
% thread::rwmutex rlock x
no such mutex "x"
-errorcode NONE
% set w [thread::rwmutex create]
> thread::rwmutex wlock $w
> thread::rwmutex wlock $w
write-locking the same read-write mutex twice from the same thread
-errorcode NONE
% set w [thread::rwmutex create]
> thread::rwmutex rlock $w
> thread::rwmutex wlock $w
write-locking a read-locked mutex
-errorcode NONE
Facts
- Capability
thread. A new interpreter does not have it until the host turns it on.- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1