I use process shared pthread_mutex_t on shared memory. I wonder what if a process lock the mutex and somehow exit, what will happen? As my experiment shows, deadlock happens, but this is a bad news. So is there a way to prevent this? Should not the mutex automatically unlocked when process exit?
Related Questions in PTHREADS
- How to create a vector of a specific class in c++ that includes thread objects in it?
- Can someone help me understand why my C webserver is throwing SIGABRT
- thread created by pthread in Linux belongs to ULT or KLT?
- how to use taskset -c option when hyperthreading/logical CPU is enabled
- How to synchronize threads with io_uring?
- happening segment fault when i use pthread_create
- I want to compile/install assimp with phtreads enabled over vcpkg on Windows. But i dont know how?
- pthread library include path on visual studio code
- How to Efficiently Parallelize AES-CTR PRNG Implementation in C Using Pthreads for Multi-Core Utilization?
- Restart Xenomai Thread if Exceed the Time
- Why is fprintf not working as intended in my code?
- Periodically trigger pthread workers and wait for completion
- How can I build a debug version of Winlibs, or just libwinpthread.dll?
- C++17/Linux: signal not unblocking blocked network socket calls in separate thread
- How can I create and reassign threads based on user input?
Related Questions in MUTEX
- Can defer recover prevent mutex Unlock?
- In Rust, how to coerce a mutex lock into a reference with identical lifetime?
- Binary Semaphore vs Mutux interview question
- Shared variable read from low priority thread in preemptive scheduling
- Ruby Threads Concurrency Issue using Mutex
- How does mutex work in multicore systems?
- why can't the following mutex be shared by multiple threads?
- Borrowing issues using variables wrapped in Arc<Mutex<>> in Rust
- Eliminating concurrency bugs with mutexes
- Returning variable by reference requires holding mutex
- Do I need mutexes for read operation only?
- Mutex doesn't stop more than one coroutine to modify or read the data
- How do I disable the eventual fairness of the Rust parking_lot crate's Mutex?
- How to prevent race condition when multiple threads are writing in the same file descriptor in C?
- How to ensure consistency in process synchronization
Related Questions in DEADLOCK
- Why sem_post() looks like blocked when using WinAPI and Semaphore to create a program that re-running again and again
- Understanding Potential Deadlock in Resource Pool Implementation Described in "Go in Action"
- Workaround for Micrometer deadlock
- How to detect deadlocks in a Go program?
- ORM Postgresql DeadLock?
- Deadlock occured but can't find it's origin
- Lock Acquisition Order in MYSQL
- The Philosophers dinning problem, why my threads are getting race conditions?
- How to ensure consistency in process synchronization
- custom mutex - all goroutines are asleep - deadlock
- How to prevent Deadlocks in Java using the Bakery Algorithm?
- Deadlock in Python garbage collection on exception
- COS/S3 python log handler causes deadlock
- mpi deadlock with matrix-vector multiplication
- Database Deadlock Prevention Wound-wait and wait-die
Related Questions in MULTIPROCESS
- Re-importing Python modules within the function being called by multiprocess?
- OpenMPI: receive int and double from multiple processes
- Exception handling through signal communication in multiprocess programs in C
- multiprocessing a keras subclassing model
- Python multiprocess pool.map takes too long for initialization
- Handling SIGTERM in Parent Process on Fork Failure - Resource Cleanup Issue
- Multiprocessing in python where only one thread (process) may use one of a set of values at one time
- Python `asyncio` using different executors for tasks with dependencies
- Resources for learning how to design a multi-process software and how to decide which approach to use
- FastAPI protecting shared variable with multiprocessing lock
- how to run this process in parallel
- how can I brute-force 5 characters in python to crack sha256 with multiprocess or multithread?
- Stucking of python multiprocessing.pool
- Open MPI failed to spawn process
- Populating and processing the same queue/list in different processes without deleting items from the queue/list
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
No, the mutex shouldn't be automatically unlocked, because the shared data protected by the mutex may be in an inconsistent state.
If you want to handle this situation, you need to use "robust mutexes". To create a robust mutex, set the mutex robustness property to
PTHREAD_MUTEX_ROBUSTby usingpthread_mutexattr_setrobust()on apthread_mutexattr_tobject that is used to initialise the mutex.If a thread or process exits while holding a robust mutex, the next call to
pthread_mutex_lock()on that mutex will return theEOWNERDEADerror. If this error is returned, your code must carefully check all the shared state protected by the mutex and fix any inconsistencies. It can then mark the state as consistent by callingpthread_mutex_consistent()on the mutex, and then continue its execution as normal.