Channel (programming)

Uses your system voice; voice and rate in settings.

Snapshot

≈ 2 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

In computing, a channel is a model for inter-thread communication and synchronization via message passing. A message may be sent over a channel, and another process or thread is able to receive messages sent over a channel it has a reference to, as a stream. Different implementations of channels may be buffered or not, and either synchronous or asynchronous.

In computing, a channel is a model for inter-thread communication and synchronization via message passing. A message may be sent over a channel, and another process or thread is able to receive messages sent over a channel it has a reference to, as a stream. Different implementations of channels may be buffered or not, and either synchronous or asynchronous. The Love2D library which uses the Lua programming language implements channels with push and pop operations similar to stacks. The pop operation will block so as long as there is data resident on the stack. A demand operation is equivalent to pop, except it will block until there is data on the stack -- A string containing code which will be interpreted by a function such as loadstring(), -- but on the C side to start a native thread. local threadCode = love.thread.getChannel("test"):push("Hello world!") function love.load() -- Start the thread. thread = love.thread.newThread(threadCode) thread:start() -- The thread will block until "Hello world!" is popped off channel test's stack. -- Because the channel can be popped from before the thread first executes, there may not be data on the stack. -- in that case use :demand() instead of :pop() because :demand() will block until there is data on the stack and then return the data. print(love.thread.getChannel("test"):demand()) -- The thread can now finish. end chan c; int x; par { c x; } c := make(chan int) go func() {c use std::sync::mpsc; use std::thread; fn main() { let (tx, rx) = mpsc::channel(); thread::spawn(move || { tx.send(123).unwrap(); }); let result = rx.recv(); println!("{:?}", result); }

Text derived from https://en.wikipedia.org/w/index.php?oldid=1378821161 under CC BY-SA 4.0; modifications have been made.