When communicating between multiple processes, with multiple channels, having ONE2ONE type channels could deadlock. We don't want that.
#include <stdio.h>
#include <unistd.h>
process print(char *label, chan<char> c, chan<int> c2) {
while (1) {
char foo = c?;
printf("%s %c\n", label, foo);
c2 ! 0;
}
}
process writer(char label, int delay, chan<char> c, chan<int> c2) {
while (1) {
usleep(delay);
c ! label;
c2?;
printf("%c\n", label);
}
}
int main() {
chan<char> c;
chan<int> c2;
par {
print("P", c, c2);
writer('A', 10e4, c, c2);
writer('B', 10e4, c, c2);
writer('C', 10e4, c, c2);
}
return 0;
}
Depending on the thread that runs first (which is not deterministic), it might deadlock or not. If using ANY2ONE_CHANNEL and ONE2ANY_CHANNEL types for c and c2 respectively, the problem is solved.
Two things need to be solved to fix this:
- statically determine which channel type to choose
- come up with a solution for
CSP_priAltselect, that only accepts ONE2ONE and ANY2ONE.
When communicating between multiple processes, with multiple channels, having ONE2ONE type channels could deadlock. We don't want that.
Depending on the thread that runs first (which is not deterministic), it might deadlock or not. If using ANY2ONE_CHANNEL and ONE2ANY_CHANNEL types for
candc2respectively, the problem is solved.Two things need to be solved to fix this:
CSP_priAltselect, that only accepts ONE2ONE and ANY2ONE.