Channel (programming): Difference between revisions

Content deleted Content added
Added Love2D as it is an open source library for Lua that uses channels and uses familiar data structures (stacks) in its channel implementation to simplify its usage.
No edit summary
Tag: section blanking
Line 3:
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 receive messages sent over a channel it has a [[reference (computer science)|reference]] to, as a [[stream (computing)|stream]]. Different implementations of channels may be buffered or not, and either synchronous or asynchronous.
 
Channels are fundamental to the [[process calculus]] approach to concurrency, and 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 [[Plan 9 from Bell Labs]]'s libthread, as well as in [[Stackless Python]] and the [[Go (programming language)|Go programming language]].
 
==Channel implementations==
Channels modeled after the CSP model are inherently [[Synchronization (computer science)|synchronous]]: a process waiting to receive an object from a channel will [[Blocking (computing)|block]] until the object is sent. This is also called [[rendezvous behaviour]].
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]] <syntaxhighlight lang="c">Channel* chancreate(int elemsize, int bufsize)</syntaxhighlight>
* sending to a channel <syntaxhighlight lang="c">int chansend(Channel *c, void *v)</syntaxhighlight>
* receiving from a channel <syntaxhighlight lang="c">int chanrecv(Channel *c, void *v)</syntaxhighlight>
 
===libthread channels===