在使用lock-condition模式以及semaphore的aquire-release 模式获取和释放锁的时候,、
获取锁显然必须按照一致的顺序,但是释放锁呢?听到一种说法:
尽管释放锁的顺序和死锁无关,但最好是以获得锁相反的顺序释放锁。
比较同意,因为目前我找不到一个正向或者反向释放锁导致的坏的情况,请大家帮忙讨论!谢谢!

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【denverbenjamin2000】截止到2008-07-20 19:04:27的历史汇总数据(不包括此帖):
    发帖的总数量:19                       发帖的总分数:1540                     每贴平均分数:81                       
    回帖的总数量:29                       得分贴总数量:3                        回帖的得分率:10%                      
    结贴的总数量:15                       结贴的总分数:1240                     
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:4                        未结的总分数:300                      
    结贴的百分比:78.95 %               结分的百分比:80.52 %                  
    无满意结贴率:0.00  %               无满意结分率:0.00  %                  
    楼主加油
      

  2.   

    获取锁显然必须按照一致的顺序,这个是肯定的。释放的时候:比如说:表操作action 1(简称A1)锁T1
    锁T2释放T2
    释放T1表操作action 2(简称A2)锁T1
    锁T2释放T2
    释放T1“最好是以获得锁相反的顺序释放锁”我的理解是:
    1.只有释放T1后,其它操作才能够锁定T1。
    2.A1中如果这里先释放T1,但是T2暂时还没有释放,其它操作就可以锁定T1,但是无法锁定T2,要等待T2释放后才可以锁定。
      

  3.   

    同步问题在java中仅占一小部分,但在并行计算领域,历史悠久。
    大家回顾一下,分布式计算领域的Edsger W. Dijkstra Prize,就会发现,这个领域有多么深入的研究,再看看500top supercomputer,就会认识到这个领域的应用是那么广阔,但个人感觉,java在这方面,还是发展阶段。Prize winning papers    * 2008: Baruch Awerbuch and David Peleg for "Sparse Partitions," in Proceedings of the 31st Annual Symposium on Foundations of Computer Science (FOCS), 503-513, October 1990.
        * 2007: Cynthia Dwork, Nancy Lynch, and Larry Stockmeyer for "Consensus in the presence of partial synchrony," Journal of the ACM, 35(2):288-323, April 1988.
        * 2006: John M. Mellor-Crummey and Michael L. Scott for "Algorithms for scalable synchronization on shared-memory multiprocessors," ACM Transactions on Computer Systems, 9(1):21-65, February 1991.
        * 2005:  Marshall Pease, Robert Shostak, and Leslie Lamport for "Reaching agreement in the presence of faults," Journal of the ACM, 27(1):228-234, April 1980.
        * 2004:  R. G. Gallager, P. A. Humblet, and P. M. Spira for "A Distributed Algorithm for Minimum-Weight Spanning Trees", ACM Transactions on Programming Languages and Systems, 5(1):66-77, January 1983.
        * 2003:  Maurice Herlihy for "Wait-Free Synchronization", ACM Transactions on Programming Languages and Systems, 13(1):124-149, January 1991.
        * 2002*:  Edsger W. Dijkstra for "Self-stabilizing systems in spite of distributed control," Communications of the ACM, 17(11):643-644, November 1974.
        * 2001*:  Michael J. Fischer, Nancy A. Lynch, and Michael S. Paterson for "Impossibility of  Distributed Consensus with One Faulty Process," Journal of the ACM, 32(2):374-382, April 1985.
        * 2000*:  Leslie Lamport for "Time, Clocks, and the Ordering of Events in a Distributed System," Communications of the ACM, 21(7):558-565, July 1978.