Question

I would like to know what user-space threading libraries (for standard C++) are available which allow for fine-grained control over application level preemptive scheduling. Target platform is POSIX but having a cross platform solution would be particularly nice.

Was it helpful?

Solution 2

Portable Runtime System has customizable user space preemptive scheduling, but is written in C.

OTHER TIPS

If it is sufficient to set priorities of threads, you can use pthreads: How to increase thread priority in pthreads?. If you want to be able to schedule manually, then you should use a cooperative threading such as longjump or http://www.gnu.org/software/pth/pth-manual.html. To use multiple processors you will need kernel threads, which you can get through pthreads or OpenMP.

Basically you should initially spawn a couple of kernel threads, pin them, and run additional cooperative threads on top of the kernel threads. Be aware that cooperative threading is non-preemptive unless you implement the preempting with timer events, but the kernel threads will be preempted. Some cooperative threading schemes do not work well with C++, specifically they may call destructors of variables on the stack when switching.

C++11 standard library has threading support, thought it relies on pthreads on Linux. You can also use pthreads directly (it is implemented in C). If you want something portable - Qt has good thread support.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top