Re: spin_lock & spin_trylock race

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

 





On Wed, Aug 25, 2010 at 1:18 PM, Lal <learner.kernel@xxxxxxxxx> wrote:
Is below code race free?

void process_context_function(void)
{
   /* interrupts enabled here */
   spin_lock(&lock);
   modify_critical_section_list();
   spin_unlock(&lock);
}

irqreturn_t a2091_intr (int irq, void *_instance)
{
   if(spin_trylock(&lock)) {
       modify_critical_section_list();
       spin_unlock(&lock);
   }
   else {
      /* skip */
   }

   return IRQ_HANDLED;
}


More specifically, can spin_lock & spin_trylock have race?

Regards
Lal


Have u ever considered mutex?   Spinlocks are fast and efficient, but anything after the spinlock MUST NOT SLEEP, but, or risk being scheduled OUT of being processed by the CPU.   Generally, in my present understanding, any locks inside the interrupt context should use spinlocks, and process context should use mutex locks, and race condition always appeared whenever the one running in process context is competing for resources with those in interrupt context - ie, avoid having locks that is cross-used in both context.

Sorry if I am wrong, comment welcomed :-).

--
Regards,
Peter Teoh

[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