Re: mutex unlock order

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

 



Hello,

On Thu, Dec 9, 2010 at 7:49 AM, Michael Blizek
<michi1@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> I have came upon an interesting situation where I am not sure about mutex
> semantics. What I want to do is something like this:
>
> mutex_lock(&global_lock);
> mutex_lock(small_lock);
>
> do_something_small_which_requires_both_locks();
> do_something_big_which_requires_only_small_lock();
>
> mutex_unlock(small_lock);
> mutex_unlock(&global_lock);
>
> I want to avoid holding the global lock while doing something_big. Can I do
> something like this:
>

Why not do this, i.e. acquire the locks in the other order, then
release the global lock first:

mutex_lock(small_lock);
mutex_lock(&global_lock);
do_something_small_which_requires_both_locks();
mutex_unlock(&global_lock);
do_something_big_which_requires_only_small_lock();
mutex_unlock(small_lock);


Regards,
-- 
Leon

--
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