锁,互斥,信号量...有什么区别? [英] Lock, mutex, semaphore... what's the difference?
本文介绍了锁,互斥,信号量...有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我听说过与并发编程有关的这些词,但它们之间有什么区别?
I've heard these words related to concurrent programming, but what's the difference between them?
推荐答案
一个线程进入被锁定的部分,并且该锁不与任何其他进程共享。
A lock allows only one thread to enter the part that's locked and the lock is not shared with any other processes.
互斥体与锁相同,但它可以是系统级的通过多个进程)。
A mutex is the same as a lock but it can be system wide (shared by multiple processes).
信号量与互斥量相同,但允许x个线程进入。
A semaphore does the same as a mutex but allows x number of threads to enter.
您还有读/写锁,允许在任何给定时间无限数量的读者或1个写者。
You also have read/write locks that allows either unlimited number of readers or 1 writer at any given time.
这篇关于锁,互斥,信号量...有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文