|
BIND statement |
Top Previous Next |
|
bind statement = "BIND", binding type, port spec, binding value; binding type = "INPUT"} | "OUTPUT"; binding value = "VALUE", "=", constant;
Normally, ports are bound by means of the CONNECT statement; ports left unbound are pointed at unique dummy channels so that attempts to send or receive messages through them cause the minimum of harm; the thread causing the attempt to communicate over the unbound port simply pauses indefinitely rather than causing failure of possibly all threads running on the processor.
The BIND statement allows you to set the contents of a port explicitly to some literal value that does not correspond to a channel.
One application of the BIND statement is to pass an integer parameter to a user task. For example, suppose the configuration file contained the following statement:
bind input event_handler[5] value=17
This value (17) could be accessed within the task event_handler using the macro PORT_BINDING, as in the following example:
#include <chan.h> main (int argc, char *argv[], char *envp[], CHAN * in_ports[], int ins, CHAN *out_ports[], int outs) { int parameter; parameter = PORT_BINDING(*in_ports[5]); ... }
This technique can be used to allow several otherwise identical tasks to behave differently. For example, tasks executing on a fast processor can have this fact indicated to them by means of a parameter value, and use a more processing-intensive algorithm for the solution of some problem. Another use of this parameter facility is to 'label' each task with a unique identifier.
|