TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Roy J. Tellason
from: Janis Kracht
date: 2004-02-18 02:18:56
subject: spinlock?

Hi Roy,

>Can any of you guys explain to me what the heck a spinlock is?  I ran across i
> in a bit of c code in a magazine article,  dealing with something going on in
> the linux kernel...

> I've also run across the term in a number of other places.  The authors just
> seemed to assume that you'd know what they meant by that.

If I understand the term correctly, it appears to be a concept I'm familiar
with under different terminology. It's used in multi-threaded programming
to cause one thread to wait while another makes use of shared resources. 
For example,  assume a multi-threaded server where all threads share the
same logging routines, in order to prevent jumbled log entries access to
the logging routines has to be syncronized,  This can't be done using file
locking because all the threads are running in the same process. One of 
the ways this syncronization can be accomplished is by having a process
attempt to lock a memory location (variable).  If it obtains the lock, it
proceeds with the logging.  If it fails to obtain the lock, it waits
(sleeps, spins it's wheels) until the thread which holds the lock releases
it.  That's a simplified view since it ignores the potential for thread
starvation, deadlocks, etc...

Take care,
Janis

--- BBBS/LiI v4.01 Flag-5
* Origin: Prism bbs (1:261/38)
SEEN-BY: 633/267 270
@PATH: 261/38 123/500 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.