[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Simplelock v.s lock
On Thu, 17 Jun 2010 16:53:38 +0200
Putrycy <putrycydestengier%gmail.com@localhost> wrote:
> Hey guys. I am a noob in netbsd. I had some experience with linux before
> During my work, ive approached a problem when i need to use a
> Linux-like spin locks.
> I found out that i need to use either lock or simplelock in NetBSD.
> My question is : what is the exact difference between those two ?
> According to the manual:
> 'struct simplelock
> Provides a simple spinning mutex. A processor will busy-wait
> while trying to acquire a simplelock. The simplelock operations
> are implemented with machine-dependent locking primitives.
> Simplelocks are usually used only by the high-level lock manager
> and to protect short, critical sections of code. Simplelocks
> are the only locks that can be used inside an interrupt handler.
> For a simplelock to be used in an interrupt handler, care must
> be taken to disable the interrupt, acquire the lock, do any pro-
> cessing, release the simplelock and re-enable the interrupt.
> This procedure is necessary to avoid deadlock between the inter-
> rupt handler and other threads executing on the same processor.
> struct lock
> Provides a high-level lock supporting sleeping/spinning until
> the lock can be acquired. The lock manager supplies both exclu-
> sive-access and shared-access locks, with recursive exclusive-
> access locks within a single thread. It also allows upgrading a
> shared-access lock to an exclusive-access lock, as well as down-
> grading an exclusive-access lock to a shared-access lock.'
> Is the only difference that simplelocks are 'turining interrupts off'
> , and the other is not ??
> Thanks in advance for any reply.
Both of them are obsoleted in 5.0, use the newer mutex API, but for the record:
a spin lock enters a loop and keeps polling the lock, and thus wasting
resources if held too long. a sleeping lock gives up execution of the thread,
and puts it into the turnstile, to be signaled when the lock is relased
NetBSD - Simplicity is prerequisite for reliability
Main Index |
Thread Index |