Difference between revisions of "Channel"

From Mesham
Jump to navigationJump to search
(Created page with ' == Syntax == channel[a,b] Where ''a'' and ''b'' are both distinct processes which the channel will connect. == Semantics == The ''channel'' type will specify that a variable…')
 
m (5 revisions imported)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
 
== Syntax ==
 
== Syntax ==
  
Line 8: Line 7:
 
== Semantics ==
 
== Semantics ==
  
The ''channel'' type will specify that a variable is a channel from process ''a'' (sender) to process ''b'' (receiver.) Normally this will result in synchronous communication, although if the ''async'' type is used then asynchronous communication is selected instead. Note that channel is unidirectional, where process a sends and b receives, NOT the otherway around.
+
The ''channel'' type will specify that a variable is a channel from process ''a'' (sender) to process ''b'' (receiver.) Normally this will result in synchronous communication, although if the ''async'' type is used then asynchronous communication is selected instead. Note that channel is unidirectional, where process a sends and b receives, NOT the otherway around.<br><br>
 +
''Note:'' By default (no further type information) all channel communication is blocking using standard send.<br>
 +
''Note:'' If no allocation information is specified with the channel type then the underlying variable will not be assigned any memory - it is instead an abstract connection in this case.
  
 
== Example ==
 
== Example ==
  
  var x:Int::allocated[multiple[]];
+
  function void main() {
var p;
+
    var x:Int::allocated[multiple[]];
par p from 0 to 2
+
    var p;
{
+
    par p from 0 to 2 {
    (x::channel[0,2]):=193;
+
      (x::channel[0,2]):=193;
    var hello:=(x::channel[0,2]);
+
      var hello:=(x::channel[0,2]);
 +
    };
 
  };
 
  };
  
 
In this case, ''x'' is a channel between processes 0 and 2. In the par loop process 0 sends the value 193 to process 2. Then the variable ''hello'' is declared and process 2 will receive this value.
 
In this case, ''x'' is a channel between processes 0 and 2. In the par loop process 0 sends the value 193 to process 2. Then the variable ''hello'' is declared and process 2 will receive this value.
  
 +
''Since: Version 0.41b''
 
[[Category:Type Library]]
 
[[Category:Type Library]]
[[Category:Composite Types]]
+
[[Category:Compound Types]]
 
[[Category:Primitive Communication Types]]
 
[[Category:Primitive Communication Types]]

Latest revision as of 15:44, 15 April 2019

Syntax

channel[a,b]

Where a and b are both distinct processes which the channel will connect.

Semantics

The channel type will specify that a variable is a channel from process a (sender) to process b (receiver.) Normally this will result in synchronous communication, although if the async type is used then asynchronous communication is selected instead. Note that channel is unidirectional, where process a sends and b receives, NOT the otherway around.

Note: By default (no further type information) all channel communication is blocking using standard send.
Note: If no allocation information is specified with the channel type then the underlying variable will not be assigned any memory - it is instead an abstract connection in this case.

Example

function void main() {
   var x:Int::allocated[multiple[]];
   var p;
   par p from 0 to 2 {
      (x::channel[0,2]):=193;
      var hello:=(x::channel[0,2]);
   };
};

In this case, x is a channel between processes 0 and 2. In the par loop process 0 sends the value 193 to process 2. Then the variable hello is declared and process 2 will receive this value.

Since: Version 0.41b