2 ms·
This is a very primitive implementation. I like it, and it looks good, but using mutexes and condition variables will be comparatively slow. You really want to,
by lionkor 4y ago
This is a very primitive implementation. I like it, and it looks good, but using mutexes and condition variables will be comparatively slow. You really want to, in theory, abuse atomics in order to "simulate" condition variables, since you avoid the possible context switch to the kernel which condition variables may have (afaik).
Still cool, but I know (from building and testing my own similar implementations) like a good bit performance will be lost here due to these context switches. For an example of a more complex, but much more efficient, thread pool implementation, check out this article on thread pools in Zig [1] (the language is secondary, its mostly pseudocode).
It goes over the need for an actual scheduler to make thread pools efficient.
1: https://zig.news/kprotty/resource-efficient-thread-pools-with-zig-3291 https://zig.news/kprotty/resource-efficient-thread-pools-wit...