From the course: Parallel and Concurrent Programming with C++ Part 1
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Recursive mutex - C++ Tutorial
From the course: Parallel and Concurrent Programming with C++ Part 1
Recursive mutex
- Olivia and I have been using this pencil as a mutex. Only one person at a time can own or have a lock on it and only that person can access our shared resource, this notepad. - If I attempt to lock the mutex while another thread has it, my thread will be blocked and I need to wait until he unlocks it so it becomes available. And if I attempt to lock the mutex, it doesn't appear to be available so my thread will just have to wait too. - It's behind your ear. You already locked it. - Oh, well, my thread can't unlock the mutex while I'm blocked waiting on it and I'll be waiting on the mutex forever because I'll never be able to unlock it. I'm stuck and so are you. If a thread tries to lock a mutex that it's already locked, it'll enter into a waiting list for that mutex, which results in something called a deadlock because no other thread can unlock that mutex. - There may be times when a program needs to lock a mutex…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.