From: Nagendra G. <nag...@go...> - 2015-01-23 17:47:07
|
This is from: http://www.experts-exchange.com/Programming/System/Linux/Q_20375101.html semaphores can be used between different processes to synchronise access to some shared object i.e. a file or shared memory. If you have two processes which require read/write access to some resource you need to make sure that both are not trying to change the shared resource at the same time. You can then use a semaphore to protect the access to the shared resource i.e each process has to acquire the semaphore before being allowed to perform an update on the shared resource. Once the update is complete the process then releases the semaphore to allow another process to access/update the shared resource. pthread_mutex_t is a similar concept but shared between multiple threads of a single process. If for example you have a multithreaded program which contains global data accessible/updatable by multiple threads then you would a mutex to protect the access in the same way. From: Daniel Povey [mailto:dp...@gm...] Sent: Friday, January 23, 2015 12:36 PM To: kal...@li... Subject: [Kaldi-developers] Fwd: sem_t I'm wondering if there is anyone on the list who is familiar with issues such as semaphores? The semaphore implementation in kaldi-semaphore.h uses two variables: pthread_mutex_t mutex_; pthread_cond_t cond_; but I just noticed there is something called sem_t, a semaphore type, from the POSIX standard. Does anyone know what portability issues this would bring, and what the reasons might be for using the two things from pthreads instead? Dan ---------- Forwarded message ---------- From: Karel Veselý <ive...@fi...> Date: Fri, Jan 23, 2015 at 6:27 AM Subject: Re: sem_t To: dp...@gm... Hi Dan, frankly, it is hard for me to answer, years ago we learned how to implement semaphore in pthreads, so I used the code I had in a school project. Perhaps sem_t can do the same job, and perhaps it internally uses same functions as my implementation. Karel. Dne 23. 1. 2015 v 4:13 Daniel Povey napsal(a): Karel, I just found out there is a semaphore type in POSIX, called sem-t. Why doesn't your semaphore code use that, do you know? Dan -- Karel Vesely, Brno University of Technology ive...@fi..., +420-54114-1300 <tel:%2B420-54114-1300> |