LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 01-29-2012, 02:23 AM   #1
rbhsrh
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Rep: Reputation: Disabled
difference between mutex_lock and mutex_lock_nested?


I was going through implementation of mutex. I have not understood when to use mutex_lock and mutex_lock_nested?

Please help me to understand the above mentioned functions.
 
Old 01-29-2012, 05:04 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
You will already understand that a mutex cannot be acquired twice (because this would lead to recursion deadlock). In the kernel, the locking correctness validator can be used to check for such errors, as well as other locking errors such as inconsistent order of mutex acquisition.

Now rather than operate on individual mutex objects, the validator instead works with 'classes' of mutexes. This is because there may be thousands of mutexes all operating on the same type of object, and it is the ordering of the acquisitions of the classes that are of most relevance to validation (for example, in general we don't care which inode mutex was acquired when doing validation).

This generalization in the validator works in most cases, but there are some classes of objects where the kernel may acquire multiple mutexes from the same class, and where the ordering does matter. In order to be able to validate these, the mutex_lock_nested was added. One can define a set of subclasses of a class that represent nesting levels, and the order of locking of the subclasses can then be validated (by calling the 'nested' mutex lock with the subclass as a parameter). It is not literally a recursive lock; the nesting occurs at the semantic level, from the point of view of the validator.

Refer to lockdep-design.txt in the kernel documentation for a more detailed explanation.

Last edited by neonsignal; 01-29-2012 at 05:06 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Making a Difference; Selling a Difference LXer Syndicated Linux News 0 09-23-2010 05:00 AM
shell script to find the difference betwwn two file and place the difference to other kittunot4u Linux - General 3 07-19-2010 04:26 AM
What is the Difference? SpaceCrusader Linux - General 5 07-15-2006 10:43 PM
Difference? Jongi Linux - Newbie 4 08-22-2003 02:21 AM
What is the difference? drewski *BSD 5 05-21-2003 03:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 03:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration