std lock In C++

In this video we will learn how to avoid deadlocks in cpp programming language: std::lock() In C++11 It is used to lock multiple mutex at the same time. And the syntax is as follow: std::lock(m1, m2, m3, m4); 1. All arguments are locked via a sequence of calls to lock(), try_lock(), or unlock() on each argument. 2. Order of locking is not defined (it will try to lock provided mutex in any order and ensure that there is no deadlock). 3. It is a blocking call. [Example:0] -- No deadlock. Thread 1 Thread 2 std::lock(m1,m2); std::lock(m1,m2); [Example:1] -- No deadlock. Thread 1 Thread 2 std::lock(m1, m2); std::lock(m2, m1); [Example:2] -- No deadlock. Thread 1 Thread 2 std::lock(m1, m2, m3, m4); std::lock(m3, m4); std::lock(m1, m2); [Example:3] -- Yes, the below can deadlock. Thread 1 Thread 2 std::lock(m1,m2); std::lock(m3,m4); std::lock(m3,m4); std::lock(m1,m2); JOIN ME ————— YouTube 🎬    / @cppnuts   Patreon 🚀   / cppnuts   COMPLETE PLAYLIST ————————————    • Introduction To C++      • STL In C++      • Multithreading In C++      • Data Structure      • Binary Search      • Factory Design Pattern in C++      • Smart Pointer In C++      • Digit Separator In C++      • std string_view in C++17 | Fastest String ...      • static_cast In C++   INTERVIEW PLAYLIST ————————————    • Structural Padding & Packing In C & C++      • How delete[] Knows How Much  To Deallocate...      • Find Kth Node From Back In Singly Linked List      • Search Element In Binary Search Tree (BST)      • Reverse An Array      • Check String Is Palindrome Or Not      • Find Set Bit In Integer Number      • Invert Binary Tree      • Bubble Sort      • Video      • What printf returns after printing? | C Pr...      • Designated Initialization In C   QUICK SHORT VIDEOS ————————————-    • C++ Short Videos      • Shorts C Programming MCQ   #threading #cpp #programming #tutorial #deadlock #computerscience #softwareengineering