thread wait
Serves the messages of the thread until a release ends it.
thread::wait
Description
The command thread::wait runs the event loop of the thread: it runs each script that other threads send, until the reference count of the thread goes to 0 with thread::release or thread::unwind. Then it returns, and the rest of the script of the thread runs. In the main thread it returns when no other thread has work: a message in its queue, a script that runs, a timer, or a channel with a handler. A thread without the capability event runs only its queue.
A thread with no script of thread::create runs thread::wait. In the main thread, thread::wait waits with no end unless another thread releases the main thread, so call it only in a thread.
Returns
An empty string.
Examples
% set t [thread::create {set ::n 1; thread::wait}]
> thread::send $t {incr ::n}
2
# After the release, the script goes on after thread::wait.
% set t [thread::create -joinable {thread::wait; thread::exit 5}]
> thread::release $t
> thread::join $t
5
Errors
% thread::wait x
wrong # args: should be "thread::wait"
-errorcode TCL WRONGARGS
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