季良 发表于 2013-7-30 13:47:23

[google面试题]How
 can
 we 
ensure
 that
 dead lock 
does
not 
occur?

宋倩倩 发表于 2013-7-30 13:56:16

Answer:There are many possible answers to this problem,but the answer theinterviewer will be looking for is this:we can prevent dead lock if we assign an order to our locks and require that locks always be acquired in order.For example,if a thread needs to acquire locks 1,5,and2,it must acquire lock1,followed by lock2,followed by lock5.That way we prevent one thread trying to acquire lock1 then lock2,and another thread trying to acquire lock2 then lock1,which could cause dead lock.(Note that this approach is not used very of ten in practice.)
页: [1]
查看完整版本: [google面试题]How
 can
 we 
ensure
 that
 dead lock 
does
not 
occur?