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 />

}<br />

status = cnf_tsput(tsd, tpname, sendMsg, tplength);<br />

printf("Master: Put '%s' complete\n", sendMsg);<br />

// Sleep 1 second<br />

sleep(1);<br />

// Terminate program<br />

printf("Master: Terminated\n");<br />

cnf_term();<br />

The following is the tuple space “Hello <strong>Synergy</strong>!” worker program:<br />

#include <br />

#include <br />

main(){<br />

int tsd;<br />

// Problem tuple space identifier<br />

int status; // Return status for tuple operations<br />

int tplength; // Length of ts entry<br />

char host[128]; // Host machine name<br />

char tpname[20]; // Identifier of ts entry<br />

char recdMsg[50]; // Message received from master<br />

}<br />

// Get host machine name<br />

gethostname(host, sizeof(host));<br />

// Open tuple space<br />

printf("Worker: Opening tuple space\n");<br />

// Open problem tuple space<br />

tsd = cnf_open("problem",0);<br />

printf("Worker: Tuple space open complete\n");<br />

// Set name to any<br />

strcpy(tpname,"*");<br />

// Read problem from problen tuple space<br />

tplength = cnf_tsread(tsd, tpname, recdMsg, 0);<br />

printf("Worker: Taking item (%s)\n", tpname);<br />

// Normal receive<br />

if (tplength > 0){<br />

printf("Worker: Took message: %s from %s\n",<br />

recdMsg, tpname);<br />

}<br />

// Terminate program<br />

printf("Worker: Terminated\n");<br />

cnf_term();<br />

Before the master <strong>and</strong> worker programs can execute these programs, a Comm<strong>and</strong><br />

Specification Language (csl) file must be created. It would be much more convenient to<br />

use a makefile to compile the programs. Examples of both are below.<br />

132

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

Saved successfully!

Ooh no, something went wrong!