Difference between Mutex, Semaphore & Spin Locks

First, remember the goal of these ‘synchronizing objects’ : These objects were designed to provide an efficient and coherent use of ‘shared data’ between more than 1 thread among 1 process or from different processes. These objects can be ‘acquired’ or ‘released’. That is it!!! End of story!!! Now, if it helps to you, let … Read more

How can I tell if another instance of my program is already running?

As Jon first suggested, you can try creating a mutex. Call CreateMutex. If you get a non-null handle back, then call GetLastError. It will tell you whether you were the one who created the mutex or whether the mutex was already open before (Error_Already_Exists). Note that it is not necessary to acquire ownership of the … Read more

Differences between System V and Posix semaphores

From O’Reilly: One marked difference between the System V and POSIX semaphore implementations is that in System V you can control how much the semaphore count can be increased or decreased; whereas in POSIX, the semaphore count is increased and decreased by 1. POSIX semaphores do not allow manipulation of semaphore permissions, whereas System V … Read more

Does SemaphoreSlim (.NET) prevent same thread from entering block?

From the documentation: The SemaphoreSlim class doesn’t enforce thread or task identity on calls to the Wait, WaitAsync, and Release methods In other words, the class doesn’t look to see which thread is calling it. It’s just a simple counter. The same thread can acquire the semaphore multiple times, and that will be the same … Read more

How to share semaphores between processes using shared memory

It’s easy to share named POSIX semaphores Choose a name for your semaphore #define SNAME “/mysem” Use sem_open with O_CREAT in the process that creates them sem_t *sem = sem_open(SNAME, O_CREAT, 0644, 3); /* Initial value is 3. */ Open semaphores in the other processes sem_t *sem = sem_open(SEM_NAME, 0); /* Open a preexisting semaphore. … Read more

Is it possible to use mutex in multiprocessing case on Linux/UNIX ?

Mutual exclusion locks (mutexes) prevent multiple threads from simultaneously executing critical sections of code that access shared data (that is, mutexes are used to serialize the execution of threads). All mutexes must be global. A successful call for a mutex lock by way of mutex_lock() will cause another thread that is also trying to lock … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)