3 ms·
Spin locks are a tough sell in a preemptable context. Say you have two processes that share some memory location. They both briefly access it for a very short t
by Skunkleton 9y ago
Spin locks are a tough sell in a preemptable context. Say you have two processes that share some memory location. They both briefly access it for a very short time, so you protect it with a spin lock. Well, what happens in the case when one of the threads is preempted while holding the lock? The other thread would try to aquire it, and just spin for its entire timeslot. No bueno. When you call spin_lock() in the kernel it actually disables preemption until you call spin_unlock() to avoid this. You can't disable preemption from userspace. There might be a use for a spin lock if you have a process that is SCHED_RR, but I haven't seen it.
- fywikyj 9y agohttp://bit.ly/2urhLeM http://bit.ly/2urhLeM
- gpderetta 9y agoYou are not wrong in general but note that there are ways to disable preemption in userspace in practice, be it SCHED_FIFO[1] or isolcpu with cpu pinning. [1] you better be careful with spinlocks and priorities here as you can livelock forever.