I think I’ve messed up my understanding of try lock and lock in mutexes. Does lock wait until it can lock, or does it just immediately lock without checking whether it was locked before?
mutex::lock() blocks until it gains access to the mutex, so if the mutex is currently owned by another thread it sleeps until it gets its chance to grab the mutex. mutex::try_lock() doesn't block but instead returns right away, returning true if it got the mutex and false if it didn't. mutex::unlock() releases ownership of the mutex, at which point if there are any blocked threads waiting on it, one of them gets ownership of the mutex while the others stay blocked and continue to wait their turn.