views:

398

answers:

4

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

+2  A: 

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.

Preet Sangha
And Locks are also in process right?
ckv
+4  A: 

In Windows critical sections are fully implemented in the user mode, and mutex should switch context to the kernel mode (that 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 critical section all other threads will be still locked. Critical sections are cannot be named so you cannot use them to synchronize several processes.

Kirill V. Lyadvinsky
+2  A: 

1) Critical Section is the bridge between User and Interlocked-operations. It uses inetrlocked-exchanged operations to lock and unlock you threads. It works faster than mutexes.

2) Mutex is a kernal object. It works not fast but has some advantages. First of all, named mutexes can be used across processes. Secondly, if the thread is terminated then mutex locked by this thread is unlocked.

Alexey Malistov
+2  A: 

Critical Sections are not kernal objects. They are not identified with any Handle. They can be only used to synchronize the threads belonging to same process. They cannot be used for synchronization across the process.

CSingleLock ( I assume you are referring this as a lock, in this context) is a wrapper class using RAII concept. It helps you to acquire the thread synchronization object (in its constructor) and call Lock and Unlock API in a easy way. ( hiding all internal details of which synchronization objects it is using).

CSingleLock when used with Critical sections, cannot be used across process. Where as Mutex can be used for this purpose.

When a thread acquires Mutex and no other threads can acquire the Mutex then the state of the Mutex is said to be in Non-Signeled state. IF the Mutex is available and no threads have acquired then it is in Signeled state.

aJ