Possiblity to request several Linux threads scheduled together (in the same time)

I’d like to be able to request Linux to schedule two or more threads in the same time. I mean today when my multi-threaded program is being executed I know that in worst case only one of my threads is being physically executed (scheduled) at a time.
Now I’d like to tell Linux: here is the list of thread Ids, please try to schedule them in the same time, possibly with core affinities.
Does such capability exist, or has someone worked on this ?

The goal is to have one or even more task threads (dedicated to tasks) running in the same time as the main thread. The main thread would give them very short tasks to execute, like storing to or searching a hash or array. Meanwhile the main thread would go on until it would reach a dependency on one of tasks’ result. If the task was really executed in parallel the dependency would not stop the main thread and the program would run faster.

With the usual scheduling scheme the tasks could be scheduled much later than the sync point and this could even run slower than a single-threaded version.


Actually, in worst case, none of your threads may be executing. Linux has plenty of its own threads that it also needs to schedule. You can always request to run multiple threads, but only by assigning a high priority to them can you hope to have them running simultaneously. No guarantees.

Assigning a core affinity to a thread is a bad idea. That could block your thread if another thread is already running on that core, and it does not relinquish. It’s typically faster to use the next available core.

You may want to look at the “real-time” system calls in Linux, but Linux doesn’t support “hard” real-time. Keep in mind that being too generous to your own threads might block some necessary Linux threads from running.


Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *