Does sem_wait/sem_post work the same as pthread_mutex_lock/unlock?
If it doesn't, what major difference they have? For coding wise, I only know that sem_wait() requires initialization which is sem_init() and pthread_mutex doesn't require it. But other than that I don't really know what is the best situation to use semaphore / mutex.
Also, If I have multiple shared data between different threads function, should I use multiple locks? For example,
If I have
linkedlist sharedtype1;
linkedlist sharedtype2;
Whenever I perform read or write on thread function on sharetype1
I use mutex1
and for sharedtype2
I use mutex2
. Or should I use single mutex/semaphore?