递归锁 [英] recursive locks

查看:115
本文介绍了递归锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

递归锁是否有用例?是否有一种绝对需要递归锁定的场景。



似乎使用起来很复杂和危险。我可以看到我们可以避免死锁(只要锁堆栈不会溢出),但是我们不想捕捉到这些问题。



也许我错过了一些东西这里。感谢任何指针。



提前感谢。

解决方案

像这个博客条目的标题:



递归锁会杀死你



我也喜欢这个引用:


http://www.thinkingparallel.com/2006/09/27/recursive-locks-a-blessing-or-a-sese/



不要使用递归互斥体。这是类似于使用安全套的性别。


最后,这里是一个非常有趣的文章,关于递归锁如何进入Posix pthreads :


http://groups.google.com/group/comp.programming.threads/msg/d835f2f6ef8aed99?hl=zh-CN&pli=1



递归互斥是一个黑客。使用它们没有问题,
但它们是拐杖。有坏腿还是图书馆?罚款,使用
拐杖。但至少要知道你正在使用拐杖,为什么?和
一次一次检查腿(或图书馆),以确保你仍然
需要拐杖。如果没有治愈,去看医生,因为
这还不行。当你没有选择时,使用
a拐杖没有任何耻辱...但是你不能在拐杖上运行得很好,而且
会减慢任何依赖你的人。 / p>

递归互斥可以成为现有库中原型线程支持
的好工具,完全是因为它可以推迟硬
部分:调用图书馆的路径和数据依赖性分析。但是,由于同样的原因,
,总是记住,直到
都没有完成,所以你可以生成一个你为此感到自豪的图书馆,那么
不会不必要地禁止整个
应用程序的并发。



Is there a use case for recursive locks? Is there a scenario that absolutely requires recursive locking.

Seems to be complicated and dangerous to use. I can see that we may avoid deadlocks (provided the lock stack doesn't overflow) but don't we want to catch such problems.

Maybe I'm missing something here. Any pointers are appreciated.

Thanks in advance.

解决方案

I like the title of this Blog entry:

Recursive locks will kill you

I also like this quote:

http://www.thinkingparallel.com/2006/09/27/recursive-locks-a-blessing-or-a-curse/

Don’t use recursive mutexes. It’s akin to sex with used condoms.

Finally, here's an extremely interesting article about how recursive locks got into Posix pthreads in the first place:

http://groups.google.com/group/comp.programming.threads/msg/d835f2f6ef8aed99?hl=en&pli=1

Recursive mutexes are a hack. There's nothing wrong with using them, but they're a crutch. Got a broken leg or library? Fine, use the crutch. But at least be aware that you're using a crutch, and why; and once in a while check out the leg (or library) to be sure you still need the crutch. And if it's not healing up, go see a doctor, because that's just not OK. When you have no choice, there's no shame in using a crutch... but you can't run very well on a crutch, and you'll also be slowing down anyone who depends on you.

Recursive mutexes can be a great tool for prototyping thread support in an existing library, exactly because it lets you defer the hard part: the call path and data dependency analysis of the library. But for that same reason, always remember that you're not DONE until they're all gone, so you can produce a library you're proud of, that won't unnecessarily contrain the concurrency of the entire application.

这篇关于递归锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆