Hi Sasha,

Alexandra (Sasha) Fedorova wrote:
> I am working on an extension to Solaris scheduler and I find myself needing 
> to acquire locks on TWO kthread structs (via thread_lock(t)) at once, i.e., 
> in a single function. I have not seen this done anywhere in Solaris kernel: 
> usually one thread lock is held at a time, and so I am concerned that getting 
> two locks on different kthread structs might lead to a deadlock. 
>
> Do you know if two kthread locks are acquired simultaneously anywhere in the 
> Solaris kernel and if so what locking protocol (if any) is followed?  Or 
> should I try to solve my problem without holding two thread locks?
>
>   
shuttle_resume() actually does this, locking the current thread first, 
and then locking the thread to be resumed. This would get chaotic if if 
were possible for both threads to be doing this to one another 
simultaneously. :) ...but in the shuttle_resume() case the other thread 
shouldn't be running...so this couldn't happen.

While i'm not aware of any locking protocol...i'm thinking that you 
could model the implementation of shuttle resume(), locking the current 
thread first (if that's one of the two threads), and then lock the other 
thread...and hopefully know at the time this happens that the other 
thread cannot be trying to do the same thing to you. :) If you are 
simply trying to grab the locks of two given threads. It's more 
difficult and you would probably need to implement a "drop all the held 
locks and backoff type scheme" if you couldn't get all the locks you wanted.

-Eric
_______________________________________________
opensolaris-code mailing list
opensolaris-code@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to