SemaphoreSlim.WaitAsync before/after try block

According to MSDN, SemaphoreSlim.WaitAsync may throw: ObjectDisposedException – If the semaphore has been disposed ArgumentOutOfRangeException – if you choose the overload which accepts an int and it is a negative number (excluding -1) In both cases, the SemaphoreSlim wont acquire the lock, which makes it unnessacery to release it in a finally block. One thing … Read more

Delete all SYSTEM V shared memory and semaphores on UNIX-like systems

Here, save and try this script (kill_ipcs.sh) on your shell: #!/bin/bash ME=`whoami` IPCS_S=`ipcs -s | egrep “0x[0-9a-f]+ [0-9]+” | grep $ME | cut -f2 -d” “` IPCS_M=`ipcs -m | egrep “0x[0-9a-f]+ [0-9]+” | grep $ME | cut -f2 -d” “` IPCS_Q=`ipcs -q | egrep “0x[0-9a-f]+ [0-9]+” | grep $ME | cut -f2 -d” “` for … Read more

Do I need to Dispose a SemaphoreSlim?

If you access the AvailableWaitHandle property, then Yes, you must call Dispose() to cleanup unmanaged resources. If you do not access AvailableWaitHandle, then No, calling Dispose() won’t do anything important. SemaphoreSlim will create a ManualResetEvent on demand if you access the AvailableWaitHandle. This may be useful, for example if you need to wait on multiple … Read more

Monitor vs Mutex

Since you haven’t specified which OS or language/library you are talking about, let me answer in a generic way. Conceptually they are the same. But usually they are implemented slightly differently Monitor Usually, the implementation of monitors is faster/light-weight, since it is designed for multi-threaded synchronization within the same process. Also, usually, it is provided … Read more

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