public member function
<mutex>

std::recursive_mutex::lock

void lock();
Lock recursive mutex
The calling thread locks the recursive_mutex, blocking if necessary

  • If the recursive_mutex isn't currently locked by any thread, the calling thread locks it (from this point, and until its member unlock is called, the thread owns the mutex).
  • If the recursive_mutex is currently locked by another thread, execution of the calling thread is blocked until completely unlocked by the other thread (other non-locked threads continue their execution).
  • If the recursive_mutex is currently locked by the same thread calling this function, the thread acquires a new level of ownership over the recursive_mutex. Unlocking the recursive_mutex completely will require an additional call to member unlock.

All lock and unlock operations on the recursive_mutex follow a single total order, with all visible effects synchronized between the lock operations and previous unlock operations on the same object.

Note that the order in which different concurrent locks are scheduled to return is unspecified, and not necessarily related to the order in which they are locked (depending on the system and library implementation).

参数



返回值



数据竞争

The recursive_mutex object is modified as an atomic operation (causing no data races).

异常安全

Basic guarantee: if an exception is thrown by this member function, the recursive_mutex object is left in a valid state. Further, a lock is never acquired by the thread that made the throwing call.

如果调用失败,将抛出system_error 异常
exception typeerror condition描述
system_errorerrc::resource_deadlock_would_occurA deadlock was detected (implementations may detect certain cases of deadlock).
system_errorerrc::operation_not_permittedThe thread does not have privileges to perform the operation.
system_errorerrc::device_or_resource_busyThe native handle type manipulated is already locked.
根据库实现的不同,此成员函数还可能抛出异常来报告其他情况。

另见