4 ms·
I hate to voice a negative opinion but there are multiple red flags in this project. There are lots of user space spinlocks in the code, for the scheduler and
by exDM69 6y ago
I hate to voice a negative opinion but there are multiple red flags in this project.
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.
- gpderetta 6y agoI think that this days windows has keyed events which are the equivalent of a futex.
- flohofwoe 6y agoOn the other hand, the project is in continuous development since 2015, created by a (game-)industry veteran and used in a (or at least one) released game. IME such projects born out of real-world requirements are much more robust (and easier to integrate) than the typical 'academic' or (worse) 'Google-scale' framework.
- exDM69 6y agoYeah, under the kind of typical workload I imagine this goes through in a gamedev environment, I don't expect it to ever hit the contention cases. 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.
- DSingularity 6y agoI agree. Absent contention those primitive are manipulated via user-space operations anyway. The condition variable even has some optimistic spinning in the NPTL implementation iirc. So basically, he is reinventing the wheel.
- pjmlp 6y agoFrom that point of view, without judging anything about enkiTS and playing devil's advocate, there are lots of software proving their value in production, without having one single line of code subjected to the all best practices that are discussed here or in conferences. So we should put aside all those YAGNI, TDD, endless review processes, and just focus on delivering actual product value.