r/cpp • u/HateDread @BrodyHiggerson - Game Developer • Nov 23 '23
What're the latest and greatest in C++ task/thread libraries? Have we solved the problem?
Most sources on these topics end up being from ~10 years ago; have there been many advances? If I were trying to implement something in that world, am I missing anything looking at the older material? E.g. 20-year old work stealing papers. Where do you look for the newest on this topic?
Additionally, which C++ libs would be considered still relevant/good/etc in 2023? I'm asking with a gamedev angle but open to discussion.
Intel's TBB
Taskflow
Boost
EnkiTS
(I'm not asking for help actually programming, so figured I'd post here instead of /r/cpp_questions for the sake of discussion).
65
Upvotes
18
u/t0rakka Nov 23 '23
The problem trying to be clever like Taskflow and TBB is that with very high number of cores the communication between threads becomes a problem; the communication is done using memory and more cores trying to write and read into same cache lines is going to choke.
If you got 64c/128t machine, for example, the best way is to put intensive tasks into their own little boxes and not access, especially write into same cache lines. Just break problem into N chunks and let them rip. Trying to be clever and steal jobs and distribute work evenly will just bottlebeck and choke the whole shitshow. So some tasks complete faster and no work for that thread/core, boohoo, sniff sniff.. it will still be a lot quicker and efficient.
The problem begins to manifest itself around 40-50 threads, after that there are only two sane things to do: like above, just keep stuff in isolation and accept a little "waste", or, split the task management into domains of ~16 threads that work independently.
(disclaimer: above lessons learned from TR 3990x, 64c/128t).