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

说说自旋锁与互斥锁的区别,以及自旋锁适用的场景 #90

Open
tbfungeek opened this issue Feb 13, 2020 · 0 comments
Open

Comments

@tbfungeek
Copy link
Owner

二者区别在于在争夺锁的过程,没获得锁的那一方的行为,互斥锁会阻塞线程睡眠等待,而自旋锁会不断尝试,直到获得锁为止。自旋锁在未获得锁的情况下会占用着CPU一直运行,在长时间未能获得锁的情况会降低CPU的效率,并且自旋锁有优先级反转的问题存在,所以自旋锁适用于内核可抢占式的系统,对于单CPU且不可抢占式的内核下仅适合于锁使用者保持锁时间比较短的情况。

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

1 participant