28.10.2014 Views

Synergy User Manual and Tutorial. - THE CORE MEMORY

Synergy User Manual and Tutorial. - THE CORE MEMORY

Synergy User Manual and Tutorial. - THE CORE MEMORY

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Synergy</strong> <strong>User</strong> <strong>Manual</strong> <strong>and</strong> <strong>Tutorial</strong><br />

entries in the tuple space similar to the example above. Active tuples are created with the<br />

eval() function. The function call:<br />

eval(“worker”, worker());<br />

would create a tuple entry with “worker” in the first field <strong>and</strong> spawn a new process that<br />

will immediately call the worker() function. Passive tuples are created <strong>and</strong> added to the<br />

tuple space with the Linda’s out() function. The function call:<br />

out(“string”, 123, 45.678);<br />

would create the tuple <strong>and</strong> add it to the tuple space.<br />

Data can be either read or removed from the tuple space. A template is used to retrieve a<br />

tuple from the tuple space by matching a pattern in the fields of a tuple’s fields. The<br />

following conditions must be met to match a template to a tuple:<br />

1. The template <strong>and</strong> tuple both must have the same number of fields.<br />

2. The template <strong>and</strong> tuple both must have the same types, values, <strong>and</strong> length of all<br />

literal values in corresponding fields.<br />

3. The template <strong>and</strong> tuple both must have matching types <strong>and</strong> lengths of all formals<br />

in the corresponding fields.<br />

A read operation, using the rd() function, leaves the tuple for other processes to access.<br />

The function call:<br />

rd(“string”, 123, ? A);<br />

reads a three entry tuple that has “string” as its first element <strong>and</strong> 123 as its second. The<br />

data in the third element is placed in the A variable. The in() function gets <strong>and</strong> removes<br />

an entry from the tuple space. The function call:<br />

in(“string”, 123, ? A);<br />

gets a three entry tuple that has “string” as its first element <strong>and</strong> 123 as its second. The<br />

data in the third element is placed in the A variable <strong>and</strong> the entry is removed from the<br />

tuple space.<br />

Programming for a tuple space is similar to programming for shared memory because all<br />

participating processes share it. However it is also similar to message passing because<br />

entries are posted <strong>and</strong> taken from it. The major benefit of this system is that participants<br />

can enter <strong>and</strong> leave the system without formerly announcing an arrival or departure.<br />

77

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!