5 ms·
Anyone know where I can read up on implementing something better than something like http://www.davidespataro.it/modern-c-concurrency-synchronizing-threads-cond
by corysama 6y ago
Anyone know where I can read up on implementing something better than something like http://www.davidespataro.it/modern-c-concurrency-synchronizing-threads-condition-variables/ http://www.davidespataro.it/modern-c-concurrency-synchronizi... without running into the kernel scheduling problems Linus ranted about?
Besides the issues like how the return values of size() and empty() can be invalidated before the functions return. And, how it would be nice to have some better support for move semantics in there.
- Const-me 6y agoI don't know, I'm generally happy with the way modern OSes (Windows 10, Linux 5.4) do kernel scheduling. OS queues rarely expose methods like size() or empty(). In their multi-consumer queues they normally only expose variants of enqueue() and dequeue(). Peeking or checking for empty size is only there for single consumer queues, like win32 message queue.
- corysama 6y agoTo be clear: My understanding of the kernel scheduling problems Linus talked about were basically that modern OSes do a very good job and people run into problems by trying to work around them. This is because the kernel will still move on doing it's job even if you don't coordinate with it. For example: when using lock-free queues you'll still get long, unpredictable pauses in your thread because it will still naturally get timesliced into a context switch eventually.
- Const-me 6y agoI’m pretty sure developers of OS kernels are aware of these shenanigans. Here’s the implementation of queues in Linux: https://github.com/torvalds/linux/blob/4334f30ebf395b204c6cbeabf371a5a998d6ba7c/ipc/mqueue.c https://github.com/torvalds/linux/blob/4334f30ebf395b204c6cb... I never worked on that kernel, but on the first sight it looks like they’re using a combination of locks and lock-free stuff there.