What is the main difference between these two Functions?
std::mutex::lock() std::mutex::try_lock()
If the mutex is not available, try_lock() returns with a corresponding code, whereas lock() snatches the mutex from the thread that currently has it.
try_lock()
lock()
lock() enforces preemption, whereas try_lock() suggests preemption.
Both attempt to acquire a lock, but lock() blocks if the mutex is not available, whereas try_lock() returns whether the mutex is available or not.
lock() has a higher privilege over try_lock(). This means that you have a better chance of acquiring a mutex with lock().
with lock()