Re:Cost of a thread in C++ under Linux
by clarry on Sunday March 01, 2020 @11:24AM
(#22457510)
Also:
* Do you have sufficiently large batches that you can efficiently assign to one thread?
If not, then you're just wasting a lot of time waking up to receive inputs, assigning them to threads (-> put them on a work queue or similar, with all the locking / atomics), and waking up a thread to pull an item (locking / atomics), process it, go to sleep...
It's easy to end up spending more time juggling tasks and switching tasks than performing any useful work.
* Do you have sufficiently large batches that you can efficiently assign to one thread?
If not, then you're just wasting a lot of time waking up to receive inputs, assigning them to threads (-> put them on a work queue or similar, with all the locking / atomics), and waking up a thread to pull an item (locking / atomics), process it, go to sleep...
It's easy to end up spending more time juggling tasks and switching tasks than performing any useful work.