LWN.net Logo

What is a spinlock?

What is a spinlock?

Posted Jan 31, 2003 18:19 UTC (Fri) by cpeterso (guest, #305)
In reply to: What is a spinlock? by perlid
Parent article: Fast reader/writer locks

With a normal lock, a thread will be put to sleep when it has to wait to obtain the lock. When the lock is available, the thread will be woken up.

As described, a thread will "spin" or "busy-wait" for a spinlock. Thus spinlocks should only be used for very short critical sections. If the spinning thread has to wait a long time, your CPU usage will hit 100% because the spinning thread is executing a very tight loop. That is obviously bad for performance.


(Log in to post comments)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds