enkiTS: A C and C++ Task Scheduler for creating parallel programs
github.com
github.com
There are lots of user space spinlocks in the code, for the scheduler and the mcsp queue. Questionable use of atomics and memory barrier orderings. NIH futex using atomics and a WINAPI semaphore for backoff. No cpu_relax hints. Not great test coverage.
This all could be achieved using mutexes and condition variables and it would have equally good best case performance (when using a futex based mutex), and it would be easier to test for reliability and it would have more predictable performance characteristics under high contention.
To be fair, this seems to be targeted at games for Windows and Xbox and I'm not sure how good the concurrency primitives (mutex, condvar) are for those platforms. Maybe it makes sense to spin wait on a gaming console. Or maybe the typical intended use case never hits the high contention cases or it doesn't matter if a thread is pre-empted when holding a spin lock.
I am not claiming this code is buggy, but 15 minutes of reading the code and tests does not convince me that it is not.
I've written and tested a lot of this kind of code and it is not straightforward. Sometimes I hit a problem after running a stress test on all CPU cores for 10 minutes. The tests/examples in this project run 10, 100 or 1000 times in a loop. That is inadequate to hit the pathological thread scheduling to to trigger race conditions with a high probability.
But it could as well use mutex/condvar because it is unlikely to be contended.
If there is a bug in the atomics code, it will manifest as sporadic performance. They are not easy to debug.
So we should put aside all those YAGNI, TDD, endless review processes, and just focus on delivering actual product value.
macOS too, the API is dispatch_async.
So far I only had bad experiences with Intel libraries, huge, opaque, bloated and difficult or impossible to use on different architectures.
They usually have very high performance code under the hood so this is a shame.
MKL, etc..
`apt-get source libtbb-dev`
The catch here is that if you ever end up needing something like this, it's far more prudent to write your own version than to learn someone else's solution.