A communication construct enabling sending of objects between execution threads. You may and should use this tag to refer either to the generic programming notion or the specific implementations in various languages or libraries. In the latter case don't forget to add the appropriate tag.
The channel construct is frequently used in multithreading programs to enable safe synchronization of execution threads and communication of objects between them.
When using this tag to refer to the specific implementation in a programming language or library, don't forget to add an additional tag to prevent confusion, for example go channel.
General References :
Wikipedia definition of the channel
Go Language :
The channel is one of the basic constructs of Go and generally behind every parallelization.
As described in Go specification :
A channel provides a mechanism for two concurrently executing functions to synchronize execution and communicate by passing a value of a specified element type.
// creation of a basic synchronous channel of strings
c := make(chan string)
// creation of a channel enabling the buffering of 100 strings before blocking
c := make(chan string, 100)
// sending of a string over the channel
c <- "somestring"
// closing of a channel
close(c)
// reception from a channel. This blocks until a string is available
s := <- c
// blocking loop over a channel until closing
for s := range c {
Java Language :
With Java 1.4, the New IO introduced the channel as an interface with many concrete implementations intended to replace the use of stream in concurrent contexts :
A channel represents an open connection to an entity such as a hardware device, a file, a network socket, or a program component that is capable of performing one or more distinct I/O operations, for example reading or writing.
A channel is either open or closed. A channel is open upon creation, and once closed it remains closed. Once a channel is closed, any attempt to invoke an I/O operation upon it will cause a ClosedChannelException to be thrown. Whether or not a channel is open may be tested by invoking its isOpen method.
Channels are, in general, intended to be safe for multithreaded access as described in the specifications of the interfaces and classes that extend and implement this interface.