Live data from Hacker News

Libcsp: a fast C concurrency library influenced by the CSP model

github.com

21–26 of 26 posts

Re: Libcsp: a fast C concurrency library influenced by the CSP model

#21
post #10

Earlier quoted context omitted.

Your skepticism made me look through the library more carefully. I came across some limitations in comparison to what Go provides: 1. As you suggest, there's no equivalent to the `select` mechanism. To perform the equivalent, you must busy loop and call `csp_chan_try_pop`. 2. It appears you cannot nest coroutines. 3. The mutex implementation does not provide an RWMutex. 4. `csp_yield` seems somewhat necessary for pra…

RB queue?

ring buffer queue [0]

[0] https://github.com/shiyanhui/libcsp/blob/48782baf0e63cbf2914...

Re: Libcsp: a fast C concurrency library influenced by the CSP model

#22
post #14

Does anyone have resources related to learning concurrency ? I've had a very short introduction to pthreads in a CS class, but it was too succinct to get any practical benefit IMO. Knowing that a mutex can be used to limit access to a shared variable is easy enough to understand. How to structure software that runs concurrent tasks is still a mystery to me. Code I've written that uses threads appears to work but I'm…

Try learning Rust? It pretty much forces you to think about safe concurrency.

https://doc.rust-lang.org/book/ch16-00-concurrency.html

Re: Libcsp: a fast C concurrency library influenced by the CSP model

#24
post #23

I wish I had a minimal version of something like this for microcontrollers (ARM Cortex M0+ and M4). Implementing event-driven code with interrupts is always a pain, even with neatly structured state machines.

You can use Protothreads[1] for this which work on anything that runs C, as they are just using setjmp/longjmp.

I would recommend FreeRTOS instead, as it has proper prempetive scheduling, context switching and wide debugger support. It's actually only 4 files[2] so not very heavyweight in either memory or stuff to learn, and has decent abstractions for cross thread communication (queues etc). Then you can write continuous code and use preemption, rather than have to code everything as a state machine and co-operatively schedule, which is painful sometimes.

[1] http://dunkels.com/adam/pt/

[2] https://www.freertos.org/Creating-a-new-FreeRTOS-project.htm...

Re: Libcsp: a fast C concurrency library influenced by the CSP model

#25

Earlier quoted context omitted.

You run multiple instances, one per CPU core.

there is a huge difference between running an instance per CPU and letting a smart scheduler orchestrate things for you.

Parent my have a StackOverFlow CV.. :)
Post reply on HN