MENU

Fun & Interesting

Mutex Try Lock

CppNuts 49,330 lượt xem 5 years ago
Video Not Working? Fix It Now

JOIN ME
—————
YouTube 🎬 https://www.youtube.com/channel/UCs6sf4iRhhE875T1QjG3wPQ/join
Patreon 🚀 https://www.patreon.com/cppnuts

COMPLETE PLAYLIST
————————————
C++ Tutorial For Beginners: https://www.youtube.com/watch?v=3IynvwjrV-U&list=PLk6CEY9XxSIAQ2vE_Jb4Dbmum7UfQrXgt
STL (Standard Template Library): https://www.youtube.com/watch?v=LyGlTmaWEPs&list=PLk6CEY9XxSIA-xo3HRYC3M0Aitzdut7AA
ThreadIng In C++: https://www.youtube.com/watch?v=TPVH_coGAQs&list=PLk6CEY9XxSIAeK-EAh3hB4fgNvYkYmghp
Data Structures: https://www.youtube.com/watch?v=7tLVMUKLu2s&list=PLk6CEY9XxSIBG2Gv6-d1WE3Uxqx94o5B2
Algorithms: https://www.youtube.com/watch?v=4FxAK1tjLto&list=PLk6CEY9XxSICTSMyFM3GxRIwiZ7uqlJ9H
Design Patterns: https://www.youtube.com/watch?v=XyNWEWUSa5E&list=PLk6CEY9XxSIDZhQURp6d8Sgp-A0yKKDKV
Smart Pointers: https://www.youtube.com/watch?v=wUzn0HljjRE&list=PLk6CEY9XxSIAI2K-sxrKzzSyT6UZR5ObP
C++14: https://www.youtube.com/watch?v=1EAL_RRCKhY&list=PLk6CEY9XxSIAloDTEauOy_ss9fEqSP4JR
C++17: https://www.youtube.com/watch?v=aH7tYWjndgk&list=PLk6CEY9XxSIAEzHd_hTO-PRD6L8XfIUzu
C++ All Type Casts: https://www.youtube.com/watch?v=HlNVgmvX1EI&list=PLk6CEY9XxSIC6I_HCjMTGf8eV2Ty0a19E


INTERVIEW PLAYLIST
————————————
C++ Interview Q&A: https://www.youtube.com/watch?v=QSuBwGmFQqA&list=PLk6CEY9XxSIDy8qVHZV-Nf-r9f2BkRZ6p
C++ Interview Q&A For Experienced: https://www.youtube.com/watch?v=p2z7SJ5MWV8&list=PLk6CEY9XxSIDVpUt0yxC0b3IqDk63U7Bg
Linked List Interview Questions: https://www.youtube.com/watch?v=M5tQ4fJMsr0&list=PLk6CEY9XxSICJ0XSI7fbQFiEpDHISJxqT
BST Interview Questions: https://www.youtube.com/watch?v=RXeI7k9rhgE&list=PLk6CEY9XxSIAOYLZRHT20Zp3sPIbMzUNk
Array Interview Questions: https://www.youtube.com/watch?v=Z2TulQg5t30&list=PLk6CEY9XxSIDApw_RB8cowBQmzrznmpTA
String Interview Questions: https://www.youtube.com/watch?v=PnhL-c36JzM&list=PLk6CEY9XxSICY0vpYUdMlv-1Gk5CzuyQQ
Bit Manipulation Questions: https://www.youtube.com/watch?v=9CWVhu38a-Q&list=PLk6CEY9XxSIC5KqCCuaIVcuuFaXfAVWy8
Binary Tree Interview Question: https://www.youtube.com/watch?v=att1zpryvCw&list=PLk6CEY9XxSIAA3F1TVDoBTE0Lx-LZ5Ym6
Sorting Algorithms: https://www.youtube.com/watch?v=Vv-gs437i2g&list=PLk6CEY9XxSICqQ9wicEpRh3jYNTtSHVOy
C++ MCQ: https://www.youtube.com/watch?v=RJqS2JwlM6E&list=PLk6CEY9XxSIAr1ig2XzKJ1XS23Pn7SVnK
C MCQ: https://www.youtube.com/watch?v=yRzEGZ-QouU&list=PLk6CEY9XxSIBs60KjvhQMtjl1UjVcJC2E
C Interview Questions: https://www.youtube.com/watch?v=RQZ9DE4nUR4&list=PLk6CEY9XxSIB9jwcI0SP_FbamuqSWxvse

QUICK SHORT VIDEOS
————————————-
C++ Short : https://www.youtube.com/playlist?list=PLk6CEY9XxSIChg28m9UnVkPpfJobvlheb
C Short : https://www.youtube.com/playlist?list=PLk6CEY9XxSIAPNa21YdP5jcwaRgEfXF4-

In this video we will learn about std::mutex::try_lock() On Mutex In C++11 Threading.
Few points to remember about the try_lock is as follows:
0. try_lock() Tries to lock the mutex. Returns immediately. On successful lock acquisition returns true otherwise returns false.
1. If try_lock() is not able to lock mutex, then it doesn't get blocked that's why it is called non-blocking.
2. If try_lock is called again by the same thread which owns the mutex, the behaviour is undefined.
It is a dead lock situation with undefined behaviour. (if you want to be able to lock the same mutex by same thread more than one time the go for recursive_mutex)

There are so many try_lock function
1. std::try_lock
2. std::mutex::try_lock
3. std::shared_lock::try_lock
4. std::timed_mutex::try_lock
5. std::unique_lock::try_lock
6. std::shared_mutex::try_lock
7. std::recursive_mutex::try_lock
8. std::shared_timed_mutex::try_lock
9. std::recursive_timed_mutex::try_lock

#threading #cpp #programming #tutorial #computerscience #softwareengineering

Comment