xxx Need more intro and description of program
typedef struct {
char str[100];
} String;
@process server(@share @reply r, @share @bag s)
{
double f;
int i;
String *tmp;
while (1) {
@resource (r, f) {
i = (int)(1000.0 * sin(f));
tmp = (String *) malloc(sizeof *tmp);
sprintf(tmp->str, "Resource got %f, writing %d
n", f, i);
@put!(s, tmp);
} @reply i;
}
}
@process client(int i, @share @reply r, @share s)
{/* @share @bag is equivalent to @share */
String str;
double v = i / 3.0;
@call(r, v, i);
sprintf(str.str, "Call sent %f, got %d
n", v, i);
@write(s, str);
}
eMain()
{
@share @reply r;
@share @bag print;
@init(r);
@init(print);
@subordinate (i @for 3) server(r, print);
@cooperate (j @for 10) client(j, r, print);
while (1) {
String *str;
/* Remove everything from the print context */
@select {
@get!(print, str) {
printf("%s", str->str);
free(str);
}
@else {
/* Only when the context is empty */
break;
}
}
}
}
xxx Discuss what's required to make a program portable over multiple architectures.
%C