Re: three locks and lock order reversal?

From: popsong old <oldpopsong_at_yahoo.com>
Date: Fri, 6 Feb 2004 10:06:16 +0800 (CST)
> If one thread does A then B, another thread does B then C, and a third thread
> does C then A you can deadlock if each thread gets the first lock and blocks 
> on the second lock.  Thread 1 wants B and holds A, thread 2 holds B and wants
> C, and thread 3 wants A and holds C.  Thread 3 will not giveup C until it 
> gets A.  Thread 1 holds A and won't give it up until it gets B.  Thread 2 
> holds B and won't give it up until it gets C which is held by thread 3.  
> Hence, deadlock.
> 
> -- 
> John Baldwin <jhb_at_FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
> "Power Users Use the Power to Serve"  =  http://www.FreeBSD.org
>

Thank you for the explanation! I only thought of two threads. So this bring me
another question: if the machine only have 2 CPUs, does it mean that this kind
of LOR is safe, provided there is no other sleep lock between A and B, B and C,
C and A?

song

_________________________________________________________
Do You Yahoo!? 
完全免费的雅虎电邮,马上注册获赠额外60兆网络存储空间
http://cn.rd.yahoo.com/mail_cn/tag/?http://cn.mail.yahoo.com
Received on Thu Feb 05 2004 - 17:06:18 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:41 UTC