On Tue, 8 Jul 2008, 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?
Hmm, this reeks a bit of what the turnstile code (turnstile_interlock) and the priority inheritance stuff would need to do, lock two threads. The stuff there is quite arcane, Bryan Cantrill blogged a bit about it a few years back that and the source comments are the best doc for it that I've seen. We've got the situation where a certain codepath needs two locks in the filesystem space quite regularly (think: rename locking source and target directories), and there's no single golden path how one prevents deadlocks in such situations - have seen both trylock() as well as state-dependent locking protocols (say, lock the alphabetically-lower pathname first, or lock the one with the higher kernel virtual address first). You're right, it's tricky. FrankH. > > > This message posted from opensolaris.org > _______________________________________________ > opensolaris-code mailing list > opensolaris-code@opensolaris.org > http://mail.opensolaris.org/mailman/listinfo/opensolaris-code > ------------------------------------------------------------------------------ No good can come from selling your freedom, not for all the gold in the world, for the value of this heavenly gift far exceeds that of any fortune on earth. ------------------------------------------------------------------------------ _______________________________________________ opensolaris-code mailing list opensolaris-code@opensolaris.org http://mail.opensolaris.org/mailman/listinfo/opensolaris-code