Subj : Re: Boss Told Me You Can't Use Semaphore, But I Have To Do Something To : comp.programming.threads From : Chris Friesen Date : Wed Jul 13 2005 03:23 pm David Schwartz wrote: > Semaphores were originally designed to be process-shared and do this in > a natural way. Mutexes were originally designed to be process-local, and > have process-shared support hacked on. For example, to create a semaphore, > you just call the semaphore create function. To create a process-shared > mutex, you have to allocate shared memory and then put the mutex in it. With semas, you have something like: semget() -- creation semctl() -- initialization semop() -- lock semop() -- unlock With process-shared mutexes you have something like: mmap() -- creation pthread_mutex_init() -- initialization pthread_mutex_lock() -- lock pthread_mutex_unlock() -- unlock pthread_mutex_destroy() -- cleanup There is a 1-to-1 mapping except for the cleanup in the mutex case. There's nothing that says a mutex is for threads only, it's just a structure in memory. Whoever has access to that memory can use the mutex. Also, I actually like the pthreads API much better than the sysV one. Chris .