Re: race conditions

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

 



Hmm.  What about this (untested, but simple) code?  It saves the flags
in one function and restores them in another, but the flags variable
is not shared with anyone else.

I think I've heard that you aren't supposed to do this, but I'm
interested to know why.  (And whether it's true!)


static spinlock_t mylock = SPIN_LOCK_UNLOCKED;

static void unlock(unsigned long flags)
{
    spin_unlock_irqrestore(&mylock, flags);
}

void demo(void)
{
    unsigned long flags;
    
    spin_lock_irqsave(&mylock, flags);
    /* use locked resource ... */
    unlock(flags);
}

-- 
--Ed L Cashin            |   PGP public key:
  ecashin@uga.edu        |   http://noserose.net/e/pgp/


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[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