News for hackers. Stuff that matters.

iririri

Re:Libmill: Go-Style Concurrency in C on Friday May 10, 2019 @04:15PM (#19881796)
I'm pretty sure it's possible to get it to look like "choose { cases... } end;" instead, which is what I did in a mostly joke library I wrote to see how far I could go with the C preprocessor:

  chan_select(2) {
  chan_case_send(c, &foo, 0):
      do_stuff();
  chan_case_recv(c, &bar, 1):
      do_other_stuff(bar);
  } chan_select_end;
But the implementation (https://github.com/iriri/libcee/blob/master/include/cee/chan...) is both horrifying and not as efficient as just doing the sane thing:

  chan_case cases[] = {
      chan_case(c, CHAN_SEND, &foo), /* unfortunately still a macro but it's basically just a struct literal */
      chan_case(c, CHAN_RECV, &bar),
  };
  switch (chan_alt(cases, 2)) {
  case 0:
      do_stuff();
      break;
  case 1:
      do_other_stuff(bar);
  }