Wednesday, December 3, 2014

Event vs Critical Section vs Mutex vs Semaphore [WinCE]

Event
criticalsection
mutex
semaphore
- Notify a thread when to perform its task.
- Indicate that an event has occurred.
- Threads in other processes can open a handle to an existing event object by specifying its name in a call to CreateEvent.
- When multiple threads have shared access to the same data, the threads can - interfere with one another.
- critical section is limited to only one process or DLL and cannot be shared with other processes
- synchronization object whose state is set to signaled when it is not owned by a thread and nonsignaled when it is
- Only one thread at a time can own a mutex object.
- Threads in other processes can open a handle to an existing mutex object by specifying the object name in a call to CreateMutex.
object's state is set to signaled when its count is greater than zero, and nonsignaled when its count is zero
- application uses a semaphore to limit the number of threads using a resource
- can be used across processes or within a single process
- To signal an event, use the SetEvent or PulseEvent function. SetEvent does not automatically reset the event object to a nonsignaled state. PulseEvent signals the event, and then resets the event.
- If another thread calls EnterCriticalSection and references the same critical section object, it is blocked until the first thread calls the LeaveCriticalSection function.
- create a handle to the critical section object by calling the InitializeCriticalSection function.
- A thread calls the CreateMutex function to create a mutex object.
- owning thread releases the mutex object by calling the ReleaseMutex function
CreateSemaphore function to create a named or unnamed semaphore object.
- thread calls ReleaseSemaphore to increase the semaphore count by one

No comments:

Post a Comment

Please add your valuable feedback and suggestion...

Note: Only a member of this blog may post a comment.