Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recursive-re-entrant-locks/ #21

Open
utterances-bot opened this issue Jan 25, 2024 · 1 comment
Open

recursive-re-entrant-locks/ #21

utterances-bot opened this issue Jan 25, 2024 · 1 comment

Comments

@utterances-bot
Copy link

递归锁的缺点

大部分情况下使用递归锁是一种很糟糕的选择。

https://mthli.xyz/recursive-re-entrant-locks/

Copy link

当你在阅读代码时,获取锁和释放锁是语义上的屏障。我们可以很自然地假设当锁被释放时不变量仍然保持不变,但在递归锁场景下这种假设并不成立。当 B 调用 A 时,A 并不能确定获取锁时不变量保持不变,也不能确定释放锁时不变量保持不变。

这里怎么理解?
递归锁不是一个线程重复获取锁的过程吗? 如果是一个线程,为什么不能保证变量操作的原子性?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants