Skip to content

Use possibly ANY2ANY channels if necessary and fix ...ANY for alts if possible #26

Description

@arian

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:

  1. statically determine which channel type to choose
  2. come up with a solution for CSP_priAltselect, that only accepts ONE2ONE and ANY2ONE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions