mutex

Concurrent access by multiple threads and global mutex

荒凉一梦 提交于 2019-12-02 06:45:31
问题 The OpenSSL FAQ states that it can be used in threaded applications: 1. Is OpenSSL thread-safe? Provided an application sets up the thread callback functions, the answer is yes. This callback functions refers to a global SSL-lock, thus if you have 2 ssl connections running these will both use this global lock. However the FAQ continues: There are limitations; for example, an SSL connection cannot be used concurrently by multiple threads. This is true for most OpenSSL objects. This indicates

Mutex ownership queue order

旧街凉风 提交于 2019-12-02 04:49:27
问题 Say, if I have three threads that all access the same mutually exclusive part via a mutex. Let me give you this example. The first thread probes the mutex and gets its ownership first: //THREAD 1 //TIME: 2013-03-13 01:00:00.000Z WaitForSingleObject(hMutex, INFINITE); //Performs the operation that lasts 50 ms ReleaseMutex(hMutex); Then 10 ms later the thread 2 also requests it: //THREAD 2 //TIME: 2013-03-13 01:00:00.010Z WaitForSingleObject(hMutex, INFINITE); //Do work ReleaseMutex(hMutex);

Solution to Deadlock: Lock Ordering

时光毁灭记忆、已成空白 提交于 2019-12-02 04:16:58
问题 In the following code a deadlock is possible if two threads simultaneously invoke the transaction() function, transposing different accounts. void transaction(Account from, Account to, double amount) { mutex lock1, lock2; lock1 = getlock(from); lock2 = getlock(to); acquire(lock1); acquire(lock2); withdraw(from, amount); deposit(to, amount); release(lock2); release(lock1); } That is, one thread might invoke transaction(checkingaccount, savingsaccount, 25); and another might invoke transaction

Concurrent access by multiple threads and global mutex

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 03:15:57
The OpenSSL FAQ states that it can be used in threaded applications: 1. Is OpenSSL thread-safe? Provided an application sets up the thread callback functions, the answer is yes. This callback functions refers to a global SSL-lock, thus if you have 2 ssl connections running these will both use this global lock. However the FAQ continues: There are limitations; for example, an SSL connection cannot be used concurrently by multiple threads. This is true for most OpenSSL objects. This indicates that an additional mutex is needed for every SSL-connection. Is this correct? Or do I not need the

Mutex status after spurious wakeup

本小妞迷上赌 提交于 2019-12-02 01:47:31
问题 Consider this basic multithreading program using pthreads. We have a main thread, creating another thread that does some work. bool done = false; mutex m; condition c; void foo() { pthread_mutex_lock(&m); //while(!done) { pthread_cond_wait(&c, &m); // Spuriously wakeup while child is doing work. // child thread has NOT unlocked the mutex yet // Do I now own the mutex? // or am I waiting for child to unlock it? //} pthread_mutex_unlock(&m); } void * child(void *arg) { pthread_mutex_lock(&m);

Mutex not releasing

别等时光非礼了梦想. 提交于 2019-12-02 01:08:37
My c# WinForm solution contains several projects including an Admin project containing frmAdmin and a User project containing frmUser. A third project contains frmTimer that has a timer that periodically launches frmUser. I want frmTimer to not launch frmUser when frmAdmin is open. I'm using a named mutex to tell frmTimer if frmAdmin is open; however, the mutex appears not to be released after frmAdmin is closed. The mutex is created in frmAdmin with code like this: public partial class frmAdmin : Form { Mutex m; protected override void OnShown(EventArgs e) { base.OnShown(e); m = new Mutex

Wanted: Cross-process synch that doesn't suffer from AbandonedMutexException

一世执手 提交于 2019-12-01 23:54:11
问题 I have several threads that acquire Mutexes and then terminate. The mutexes are stored in a main repository, and are properly released when the program exists. However, when the thread that allocated a Mutex exists, the mutex gets released automatically, and subsequent acquire AbandonedMutexException (also according to the documentation). How can I avoid this exception, and keep using a Mutex even after the allocating thread finished? Is there another, more appropriate synchronization

Wanted: Cross-process synch that doesn't suffer from AbandonedMutexException

一世执手 提交于 2019-12-01 22:08:52
I have several threads that acquire Mutexes and then terminate. The mutexes are stored in a main repository, and are properly released when the program exists. However, when the thread that allocated a Mutex exists, the mutex gets released automatically, and subsequent acquire AbandonedMutexException (also according to the documentation ). How can I avoid this exception, and keep using a Mutex even after the allocating thread finished? Is there another, more appropriate synchronization construct in .Net that doesn't have this limitation. Note - I am looking for a cross-process synch mechanism

Linux pthread mutex and kernel scheduler

左心房为你撑大大i 提交于 2019-12-01 21:21:57
With a friend of mine, we disagree on how synchronization is handled at userspace level (in the pthread library). a. I think that during a pthread_mutex_lock, the thread actively waits. Meaning the linux scheduler rises this thread, let it execute his code, which should looks like: while (mutex_resource->locked); Then, another thread is scheduled which potentially free the locked field, etc. So this means that the scheduler waits for the thread to complete its schedule time before switching to the next one, no matter what the thread is doing. b. My friend thinks that the waiting thread somehow

clarifications on full memory barriers involved by pthread mutexes

夙愿已清 提交于 2019-12-01 21:09:34
I have heard that when dealing with mutexes, the necessary memory barriers are handled by the pthread API itself. I would like to have more details on this matter. Are these claimings true, at least on the most common architectures around? Does the compiler recognize this implicit barrier, and avoids reordering of operations/read from local registers when generating the code? When is the memory barrier applied: after successfully acquiring a mutex AND after releasing it? The POSIX specification lists the functions that must "synchronize memory with respect to other threads" , which includes