What is the difference between mutex's and semaphore's ? From looking at descriptions of them in previous threads they seem to have extremly similar purposes?
What is the difference between mutex's and semaphore's ? From looking at descriptions of them in previous threads they seem to have extremly similar purposes?
chris
With Win32 at least, the main difference is that a mutex is either owned or not. If the mutex is owned when a thread/process tries to acquire it, the thread will block.
A semaphore has a counter. You can specify a number greater than 1. Thus if a thread tries to get the semaphore, (bumping the counter), and getting it will not exceed the maximum, the thread can continue. Several threads/processes can own the same semaphore at the same time.
Thus a semaphore can be made to look like a mutex, but not the other way round. They have similar functionality otherwise.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.