Re: race conditions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jun 10, 2004 at 10:40:32 +0200, Jan Hudec wrote:
> The key thing to note is, that spinlock does a busy waiting. Something
> like "while(lock);" (careful crafting in assembly is necessary for it to
> work, of course). So only the other CPU on SMP can ever release it
> (that's why spinlocks compile to nothing in non-preemptable UP kernel).
> 
> If interrupt handler ever need the lock, you need the
> _irqsave/_irqrestore variant, which clears interrupt flag. So the
> interrut simply can't happen when the lock is held.
> 
> Note however, that many functions are not called from interrupt, but
> rather from scheduler -- and that won't run when you are in kernel mode
> unless you call schedule(). (In preemptable kernel it might happen, but
> holding spinlock prevents preemption.)

Sorry for replying to myself, but I forgot about one thing. There is
the spin_lock_bh/spin_unlock_bh variant, that does not disable
interrupts, but does disable bottom-halves. Not really sure where
exactly the difference lies, but I believe it's appropriate for most
hooks.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux