目的 :access serialization between threads.
应用对象:an object, data structure or section of code
best to use a mutex with a QMutexLocker since this makes it easy to ensure that locking and unlocking are performed consistently.
说明:如果 lock() 之后,发生了 exception,那么,如果没有 handle 这个 exception,或者 exception 处理中没有 unlock,那么,这个 Mutex 永远处于 lock 的 状态。其他想要 获取 lock 的 thread 如果使用的是 lock() (注意:有 non blocking 的 tryLock( timeOut) ) , 那么,thread 就会 blocking 在这里。
Recursive Mode vs Non-recursive Mode
Calling this function multiple times on the same mutex from the same thread is allowed if this mutex is a recursive mutex.
说明:一般,我们都是将同一个 Mutex 给不同的 thread , threads 之间 争取mutex。而 Recursive,则是 在同一个thread中,进行 锁/ 非锁。
如果 non-recursive 的 进行 recursive 式地操作,就会:
dead-lock when the mutex is locked recursively.