Re: recursive locking in linux?

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

 



> 
> I may be wrong, but from what I understand, the count passed in the
> semaphore initialization
> 
> sema_init(sem, count);
> 
> is the number of threads that are allowed to hold the semaphore
> simultaneously (no of threads that are allowed to enter their critical
> sections simultaneously). So can't a semaphore be actually held
> recursively?

having multiple holders doesn't imply allowing recursion!

just think of this: say you set the count such that 2 holders are
allowed.

your code then does

down(&sem);
....
down(&sem);

and most of the time this will work.

until another instance of your code runs in parallel:

cpu 0               cpu 1

down(&sem);
                    down(&sem)
...
                    ....

down(&sem); <- dead
		    down(&sem);  <- dead


at which point you're very deadlocked.

-- 
if you want to mail me at work (you don't), use arjan (at) linux.intel.com
Test the interaction between Linux and your BIOS via http://www.linuxfirmwarekit.org


--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at 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