锁释放的顺序

denverbenjamin2000 2008-07-20 07:04:39
在使用lock-condition模式以及semaphore的aquire-release 模式获取和释放锁的时候,、
获取锁显然必须按照一致的顺序,但是释放锁呢?听到一种说法:
尽管释放锁的顺序和死锁无关,但最好是以获得锁相反的顺序释放锁。
比较同意,因为目前我找不到一个正向或者反向释放锁导致的坏的情况,请大家帮忙讨论!谢谢!
...全文
873 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
denverbenjamin2000 2008-09-08
  • 打赏
  • 举报
回复
希望讨论,明晚结贴:)
爱摸鱼de老邪 2008-08-02
  • 打赏
  • 举报
回复
mark and up~~~~~
  • 打赏
  • 举报
回复
高手,都没听过
reality 2008-07-21
  • 打赏
  • 举报
回复
全凭主观
wzh0439 2008-07-21
  • 打赏
  • 举报
回复
up
denverbenjamin2000 2008-07-21
  • 打赏
  • 举报
回复
同步问题在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.
jishu_vip 2008-07-21
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jdlsfl 的回复:]
最好是以获得锁相反的顺序释放锁
[/Quote]

所谓最好,也就是说你也可以不这样做,没有什么特别严重的影响。

但是最好这样去做。原因避免无谓的等待。
jishu_vip 2008-07-21
  • 打赏
  • 举报
回复
获取锁显然必须按照一致的顺序,这个是肯定的。

释放的时候:

比如说:

表操作action 1(简称A1)

锁T1
锁T2

释放T2
释放T1

表操作action 2(简称A2)

锁T1
锁T2

释放T2
释放T1

“最好是以获得锁相反的顺序释放锁”我的理解是:
1.只有释放T1后,其它操作才能够锁定T1。
2.A1中如果这里先释放T1,但是T2暂时还没有释放,其它操作就可以锁定T1,但是无法锁定T2,要等待T2释放后才可以锁定。
denverbenjamin2000 2008-07-20
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jdlsfl 的回复:]
最好是以获得锁相反的顺序释放锁
[/Quote]
什么叫最好,收益是什么?有没有极端的情况,好在哪里,最坏是什么情况。比如说,开销?
有没有严格的说法
jdlsfl 2008-07-20
  • 打赏
  • 举报
回复
最好是以获得锁相反的顺序释放锁

62,616

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧