JOIN ME
—————
YouTube 🎬 [ Ссылка ]
Patreon 🚀 [ Ссылка ]
COMPLETE PLAYLIST
————————————
C++ Tutorial For Beginners: [ Ссылка ]
STL (Standard Template Library): [ Ссылка ]
ThreadIng In C++: [ Ссылка ]
Data Structures: [ Ссылка ]
Algorithms: [ Ссылка ]
Design Patterns: [ Ссылка ]
Smart Pointers: [ Ссылка ]
C++14: [ Ссылка ]
C++17: [ Ссылка ]
C++ All Type Casts: [ Ссылка ]
INTERVIEW PLAYLIST
————————————
C++ Interview Q&A: [ Ссылка ]
C++ Interview Q&A For Experienced: [ Ссылка ]
Linked List Interview Questions: [ Ссылка ]
BST Interview Questions: [ Ссылка ]
Array Interview Questions: [ Ссылка ]
String Interview Questions: [ Ссылка ]
Bit Manipulation Questions: [ Ссылка ]
Binary Tree Interview Question: [ Ссылка ]
Sorting Algorithms: [ Ссылка ]
C++ MCQ: [ Ссылка ]
C MCQ: [ Ссылка ]
C Interview Questions: [ Ссылка ]
QUICK SHORT VIDEOS
————————————-
C++ Short : [ Ссылка ]
C Short : [ Ссылка ]-
In this video we will learn about Recursive Mutex In C++ (std::recursive_mutex). it is very helpful when we have to put lock in recursive function calls.
Few points to remember about recursive mutex is as follows:
0. It is same as mutex but, Same thread can lock one mutex multiple times using recursive_mutex.
1. If thread T1 first call lock/try_lock on recursive mutex m1, then m1 is locked by T1, now
as T1 is running in recursion T1 can call lock/try_lock any number of times there is no issue.
2. But if T1 have acquired 10 times lock/try_lock on mutex m1 then thread T1 will have to unlock
it 10 times otherwise no other thread will be able to lock mutex m1.
It means recursive_mutex keeps count how many times it was locked so that many times it should be unlocked.
3. How many time we can lock recursive_mutex is not defined but when that number reaches and if we were calling
lock() it will return std::system_error OR if we were calling try_lock() then it will return false.
BOTTOM LINE:
0. It is similar to mutex but have extra facility that it can be locked multiple time by same thread.
1. If we can avoid recursive_mutex then we should because it brings overhead to the system.
2. It can be used in loops also.
#threading #cpp #programming #tutorial #computerscience #softwareengineering
Recursive Mutex In C++
Теги
recursive_mutexstd::recursive_mutexcall mutex multiple timesthreading in c++c++ tutorial for beginnersmultithreadingthreadsthreadingrecursive mutexhow to use recursive mutexlock with recursionhow to lock in recursionmutexc++programmingcodingcoderecursion in programmingrecursion in threadingc++ programmingc++ tutorial