Live data from Hacker News

Mill: Go-style concurrency in C

millc.org

21–30 of 54 posts

Re: Mill: Go-style concurrency in C

#21
post #5
post #3

How's it work under the hood?

Getcontext/setcontext has always allowed for coroutines in C. This just adds a sugar layer of nonblocking functions that allows a runtime layer to switch between contexts (coroutines), just like Go.

The ucontext stuff is nice but why was it deprecated?

It's generally not a problem on x86, but in my experience for other platforms, it gets messy quickly.

It would be nice if a replacement or a "de-deprecated" was around.

Re: Mill: Go-style concurrency in C

#22
post #15

Finally, something that purports to have Go-style concurrency that actually provides the equivalent of select{}! Lots of things just provide chans, which are fancy thread-safe queues and are fairly easy to implement. Getting select{} right is the tricky (and powerful) part.

Is this specific to what Go offers, or is it just a CSP implementation? I can't tell from a glance at the page, but let's give credit where credit is due if it's coming from Hoare's ideas.

it's CSP as extended by golang, i.e. with channels rather than named processes.

Re: Mill: Go-style concurrency in C

#23
post #5
post #3

How's it work under the hood?

Getcontext/setcontext has always allowed for coroutines in C. This just adds a sugar layer of nonblocking functions that allows a runtime layer to switch between contexts (coroutines), just like Go.

I'm not very good at C, but from my understanding this library uses longjmp functions which means it's cooperative multithreading rather than preemptive isn't it?

Re: Mill: Go-style concurrency in C

#24
post #22

Earlier quoted context omitted.

Is this specific to what Go offers, or is it just a CSP implementation? I can't tell from a glance at the page, but let's give credit where credit is due if it's coming from Hoare's ideas.

it's CSP as extended by golang, i.e. with channels rather than named processes.

Is this how the term OO got degenerated?

In Communicating Sequential Processes, you only communicate via messages (C) & the processes (P) sequentially (S) run to completion.

Go is not CSP. It is fair to say it was inspired by CSP. Go has a preemptive scheduler, and passing shared memory references is idiomatic and at times unavoidable.

Re: Mill: Go-style concurrency in C

#25
post #5

Earlier quoted context omitted.

Getcontext/setcontext has always allowed for coroutines in C. This just adds a sugar layer of nonblocking functions that allows a runtime layer to switch between contexts (coroutines), just like Go.

I'm not very good at C, but from my understanding this library uses longjmp functions which means it's cooperative multithreading rather than preemptive isn't it?

correct

Re: Mill: Go-style concurrency in C

#29

  $ gcc -o test test.c mill.c
  mill.c:221:13: error: conflicting types for 'wait'
   static void wait(int fd, short events) {
               ^
  In file included from /usr/include/stdlib.h:65:0,
                   from mill.c:33:
  /usr/include/sys/wait.h:248:7: note: previous declaration of 'wait' was here
   pid_t wait(int *) __DARWIN_ALIAS_C(wait);
         ^

Re: Mill: Go-style concurrency in C

#30
post #29

$ gcc -o test test.c mill.c mill.c:221:13: error: conflicting types for 'wait' static void wait(int fd, short events) { ^ In file included from /usr/include/stdlib.h:65:0, from mill.c:33: /usr/include/sys/wait.h:248:7: note: previous declaration of 'wait' was here pid_t wait(int *) __DARWIN_ALIAS_C(wait); ^

Are you on OS X? he says it's only expected to work on linux...
Post reply on HN