difference mutex vs. semaphore?
hiho@ll
i'm reading a bit about semaphores and here i read that a mutex is simply a binary semaphore Q1: is it correct that a mutex is a binary semaphore? Q2: if yes, does it mean the following example is correct? process 1 creates a mutex (pthread_mutex_init()) P1 forks 2 processes using fork(); now we have P2 and P3 forked by P1 P1,P2 and P3 have the initalized mutex all these three process are waiting for some data on a TCP server socket and write this to a shared memory (that's why i need a mutex or a semaphore) so P2 gets the connection, locks the mutex, writes the data to the shared memory and unlocks the mutex if P2 has locked the mutex using pthread_mutex_lock(); what happens if P3 does pthread_mutex_lock(); on the same mutex included by the fork of P1? will P3 wait until it's unlocked OR does it get the lock because P3 and P2 are complete different processes? Q3: if no, could anybody post the few lines used to lock and unlock a semaphore? i have this, but i have absolutly no idea if this is correct: Code:
int SemaphoreMutex::lock(){ btw: the code above is from my own SemaphoreMutex class i wrote until i read that mutex is a binary semaphore, that's why i post the whole stuff here thx@ll |
Re: difference mutex vs. semaphore?
Quote:
Quote:
Quote:
|
All times are GMT -5. The time now is 03:30 PM. |