My question is, since "[[combinable]]" is possible without "[[combine]]" but "[[combine]]" requires "[[combinable]]" then "[[combinable]]" only is a decoration with no meaning? Nothing is combined with "[[combinable]]" only?If a function complies to this format then it can be marked as combinable by adding the combinable attribute
If so, should this be warned about by the compiler? I was made aware of "[[combine]]" only recently (and then as a substitute for placed par), my eyes have read about "[[combine]]" (in [2]) but it never fastened in my gray cells. For me, at least, I would in this case have needed that warning.
Or is "[[combinable]]" by itself (to tell that it certainly is combinable) considered an important decoration that it stands by itself? Like used in a library?
Code: Select all
// Based on code by XMOS [1], expanded with a chan
#include <platform.h>
#include <stdio.h>
interface ifa {
void send (int x);
};
[[combinable]]
void ser (server interface ifa i) {
while (1) {
select {
case i.send(int x): {
printf("%d\n", x);
break;
}
}
}
}
[[combinable]]
void cli (client interface ifa i, chanend x) {
timer t;
int s;
int first = 1;
t :> s;
while (1) {
select {
case first => t when timerafter(s) :> void: {
i.send(123);
x <: 123;
first = 0;
break;
}
}
}
}
// From [2]
// A combinable function must obey the following restrictions:
// * The function must have void return type.
// * The last statement of the function must be a while(1) statement containing
// a single select statement.
// If a function complies to this format then it can be marked as combinable by adding
// the combinable attribute:
[[combinable]] // Not needed, makes no difference
void eat (chanend x[2]) {
int val;
while (1) {
select {
case x[int i] :> val: {
break;
}
}
// val++; // Not legal in [[combinable]]
}
}
int main (void) {
interface ifa i[2];
chan x[2];
par {
eat(x); // Cannot be used within the [[combine]] below. Both tasks cannot be combined
// Using the combine attribute instead of core placement
// Under the assumption that there isn't an explicit initial handshake, and guarded functions aren't used
[[combine]] // With this: one core, one timer and one chanend less
par {
cli (i[0],x[0]);
cli (i[1],x[1]);
}
[[combine]] // With this: one core and one timer less
par (int j = 0; j < 2; j++) {
ser (i[j]);
}
}
return 0;
}
[2] XMOS Programming Guide