[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: semaphore and spin locks
Hi Werner,
> > A spin lock is a primitive mechanism to prevent two or more
> > processes accessing a certain data structure at the same time. The
> > lock is an integer that's initially set to 0. A process which wants
> > to enter the critical area has to set the lock to 1 using an atomic
> > "if 0 then set 1"-operation. If the lock is in use, the process has
> > to busy-wait, spinning in a tight loop. ==> CPU-time-consuming if
> > you have to wait long, but very efficient if you don't have to
> > wait.
>
> Spin locks only work in a multiprocessor environment. If you use it
> in a unprocessor environment, then the waiting process would keep
> running in a spin and have no chance to release it and the whole
> kernel would hang.
When you say `process' do you mean a normal Unix process? If so, the
kernel will pre-empt it whilst it's in its busy loop and the other,
spin-lock holding, process will get a chance to release it.
Or does `process' mean something running as part of the kernel and not
pre-emptable in this case?
Ralph.
-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
IRC Channel: irc.openprojects.net / #kernelnewbies
Web Page: http://www.kernelnewbies.org/