beetlebug▾
/

thread transfer

Moves a channel to another thread.

thread::transfer ID CHANNEL

Description

The command thread::transfer moves CHANNEL from the calling thread to the thread ID. The channel keeps its name, and it is gone from the calling thread. A file and a socket move. A server socket, a command pipeline, and a channel that the interpreter shares, such as stdout, stay. The move removes the fileevent handlers of the channel. Between a parent and a thread of the level process, the descriptor and its buffered input move.

The commands of the channels need the capability channels, as each channel does, and exist on Linux, macOS, and Windows. The examples of this page run with --allow thread --allow channels,file.

Arguments

ArgumentTypeDefaultDescription
IDthread idrequiredThe thread that gets the channel.
CHANNELchannel namerequiredA channel of the calling thread.

Returns

An empty string.

Examples

% set t [thread::create]
> set f [open note.txt w]
> thread::transfer $t $f
> thread::send $t [list puts $f hello]
> thread::send $t [list close $f]
> set g [open note.txt]
> set line [gets $g]
> close $g
> set line
hello

Errors

% thread::transfer
wrong # args: should be "thread::transfer id channel"
-errorcode TCL WRONGARGS

% thread::transfer [thread::create] nochan
can not find channel named "nochan"
-errorcode NONE

% thread::transfer [thread::create] stdout
channel is shared
-errorcode NONE

% thread::transfer tid0x99 stdout
thread "tid0x99" does not exist
-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

See also