Content deleted Content added
Aclassifier (talk | contribs) m Blocking_(scheduling) does not exist any more--~~~~ |
Added a few examples of channels, and cleaned up some wording that was specific to only one specific implementation. |
||
Line 1:
{{About-distinguish|software interprocess communication|Channel (communications)}}
In computing, a '''channel''' is a model for [[interprocess communication]] and [[synchronization]] via [[message passing]]. A message may be sent over a channel, and another process or thread is able to synchronously receive messages sent over a channel it has a [[reference (computer science)|reference]] to, as a [[stream (computing)|stream]].▼
▲In computing, a '''channel''' is a model for [[interprocess communication]] and [[synchronization]] via [[message passing]]. A message may be sent over a channel, and another process or thread is able to
Channels are fundamental to the [[process calculus]] approach to concurrency, and first originated in [[communicating sequential processes]] (CSP), a formal model for concurrency, and has been used in many derived languages, such as [[occam (programming language)|occam]], and [[Limbo programming language]] (via [[Newsqueak]] and the [[Alef programming language]]). They are also used in the [[C programming language]] threading library libthread, and in [[Plan 9 from Bell Labs]], which uses libthread, as well as in [[Stackless Python]] and the [[Go programming language]].
Line 5 ⟶ 7:
==Channel implementations==
Typical supported operations are presented below using the example of the [[libthread]] channel API.
* Channel creation of fixed or variable size, returning a [[reference]] or [[Reference (computer science)|handle]] <source lang="c">Channel* chancreate(int elemsize, int bufsize)</source>
Line 13 ⟶ 15:
===libthread channels===
The [[Multithreading (computer architecture)|Multithreading]] library, [[libthread]], which was first created for the operating system [[Plan 9 from Bell Labs|Plan 9]]
===OCaml events===
The [[OCaml]] event module offers typed channels for synchronization. When the module's send and receive functions are called, they create corresponding send and receive events which can be synchronized.
== Examples ==
=== XMOS XC ===
The [[XMOS|XMOS]] programming language [[XC (programming language)|XC]] provides a primitive type "chan" and two operators "<:" and ":>" for sending and receiving data from a channel. <ref>https://www.xmos.com/node/17653?version=&page=23</ref>
In this example, two hardware threads are started on the XMOS, running the two lines in the "par" block. The first line transmits the number 42 through the channel while the second waits until it is received and sets the value of x. The XC language also allows asynchronous receiving on channels through a select statement.
<source lang="c">
chan c;
int x;
par {
c <: 42;
c :> x;
}
</source>
=== Go ===
This snippet of Go code performs similarly to the XC code. First the channel c is created, then a goroutine is spawned which sends 42 through the channel. When the number is put in the channel x is set to 42. Go allows channels to buffer contents, as well as non blocking receiving through the use of a select block.<ref>https://golang.org/doc/effective_go.html#channels</ref>
<source lang="go">
c := make(chan int)
go func() {c <- 42}()
x := <- c
</source>
== Applications ==
|