锁,互斥和关键部分之间的区别 [英] Difference between Locks, Mutex and Critical Sections
问题描述
现在有一个关于Mutex和Critical节之间的区别的问题,但它不处理Locks。
There is an existing question regarding difference between Mutex and Critical section but it does not deal with Locks also.
所以我想知道是否可以使用Critical节
So i want to know whether Critical sections can be used for thread synchronisation between processes.
推荐答案
还有什么意思是信号状态和非信号状态。方案
在Windows临界区(主要)在用户模式下实现,互斥体将切换上下文到内核模式(这是慢)。如果线程在拥有互斥体时终止,则互斥体被称为被抛弃。互斥体的状态被设置为用信号通知,并且下一个等待线程获得所有权。在具有临界段的相同情况下,所有其他线程将保持阻塞。关键部分无法命名,因此您无法使用它们来同步多个进程。
In Windows critical sections are (mostly) implemented in user mode, and a mutex will switch context to kernel mode (which is slow). If a thread terminates while owning a mutex, the mutex is said to be abandoned. The state of the mutex is set to signaled, and the next waiting thread gets ownership. In the same situation with a critical section all other threads will remain blocked. Critical sections cannot be named so you cannot use them to synchronize several processes.
这篇关于锁,互斥和关键部分之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!