I know that the implementation of threads in the Linux kernel and libc went through big changes in the past. What is the best way to use threads today from C programs? (I don’t even know if there is more than one API that I can use — I just know pthreads)
I don’t care too much about old kernels and libc versions, but I do care about making efficient use of multiple cores and about portability (I may want my code to also work on other Unixes).
If I just use Posix threads as described in man 7 pthreads and restrict my code to the POSIX API will that be OK?
edit: thanks to all who answerd. I did think of using some available thread pool library, but for this project this really isn’t an option.
For the most part, yes. That’s the point of POSIX. Each platform you plan to port to (including down to the OS, kernel number, and architecture) may have some differences that you’ll need to be aware of. This is your homework 🙂
Also, as a piece of advice, frameworks like Qt and library packages like Boost make a lot of this work more elegant. If you can integrate them, I highly recommend it.