3 ms·
> The sched_yield() puts the calling thread to sleep and at the back of the scheduler’s run queue. Not necessarily, but it is fine for this purpose I suppose.
by 01100011 7y ago
> The sched_yield() puts the calling thread to sleep and at the back of the scheduler’s run queue.
Not necessarily, but it is fine for this purpose I suppose. See https://news.ycombinator.com/item?id=21959692 https://news.ycombinator.com/item?id=21959692
Glad to see lock hierarchies mentioned. Barriers are new to me so that was nice.
IMO, it would be nice to at least have a mention of lock-free techniques and their advantages and disadvantages.
- agapon 7y agoRegarding sched_yield, another common (and, IMO, superior) approach to that issue is to drop the first lock and then acquire the second lock after the try-lock on it failed. Then you drop the second lock and retry the whole sequence again.
- Joker_vD 7y agoThe main disadvantage of lock-free techniques is that you have to write code without any critical sections, that is, you have to properly manage arbitrary interleaving of actions. It's hard enough to manage staleness/inconsistency of data at high (business logic) level, never mind the low level where the code is not even executed in the written order.
- scott_s 7y agoAgreed that sched_yield() is unlikely to be the right approach. A better approach is to use nanosleep() with an exponential backoff.