简体   繁体   中英

Cross-platform concurrency lib in ISO C

I want to make, or find, a simple, platform independent concurrency (aka threading) lib for C. I want to implement this without the use of OS-dependent threading APIs. It doesn't need to be "true threading", which is why I avoided the use of the term. A program implementing this library should appear as a single process to the OS.

I've looked into a few options, such as OpenMP, hacky pthreads implementations for Windows, Intel Cilk Plus, variations on Duff's device (which looks promising), and so forth. I've scoured this website for leads. It's time to forge my own way.

I have narrowed it down. I want to do this in as-close-to-standard C as possible (prefer to avoid C11, Boost, etc.) Ideally I'd like to do this without the use of external libraries at all. If they must be used, they must not use runtimes.

I have all confidence that I can pull this off, if I know where to start. I'm not an expert in C, but I am a very capable self-teacher. What I'm looking for is advice, pointers, or thoughts on implementing this library.

Current thoughts: I should fake or re-implement the shared memory model of assembly, with program counter, return pointers, etc. Call me crazy...

Relevant: Threading Implementation (the first answer.) I'm looking for more like this.

Also relevant: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=54489

I once built a threading subsytem (co-operative) in Turbo C using just setjmp and longjmp (and a little asm for mucking about with stacks of course) - it's not something I'd do again. It can be done but your desire to not use non-standard C is unwise in my opinion.

We use pthreads (and pthreads w32 is more than adequate on Windows platforms) and that's about as cross-platform as you can get until all those wonderful C11 threading features are supported everywhere. My advice is to rethink your aversion - you're setting yourself up for a world of pain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM