Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Locks, Mutex and Critical Sections

There is an existing question regarding difference between Mutex and Critical section but it does not deal with Locks also.

So i want to know whether Critical sections can be used for thread synchronisation between processes.

Also what is meant by signalled states and non-signalled states

like image 873
ckv Avatar asked May 11 '10 06:05

ckv


Video Answer


2 Answers

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.

like image 50
Kirill V. Lyadvinsky Avatar answered Oct 30 '22 01:10

Kirill V. Lyadvinsky


CriticalSections are in process. Named mutexes can be used across processes

Lock is a general term and as such I wouldn't know which platform you mean. For example in C# a lock primitive is a Critical Section.

like image 24
Preet Sangha Avatar answered Oct 30 '22 00:10

Preet Sangha