mutex

作者: hshg | 来源:发表于2023-04-26 15:44 被阅读0次
  1. std::mutex: This is the most basic type of mutex in C++. It provides mutual exclusion between threads by allowing only one thread to acquire the lock at a time. If a thread attempts to acquire the lock while it is already held by another thread, the thread will block until the lock is released.

  2. std::recursive_mutex: This is a type of mutex that allows a thread to acquire the lock multiple times without deadlocking. If a thread already holds the lock, it can acquire the lock again without blocking, as long as it releases the lock the same number of times that it acquired it.

  3. std::timed_mutex: This is a type of mutex that allows a thread to wait for a specified period of time to acquire the lock. If the lock is not available within the specified time period, the thread will return an error.

  4. std::recursive_timed_mutex: This is a combination of std::recursive_mutex and std::timed_mutex. It allows a thread to acquire the lock multiple times without deadlocking, and also allows a thread to wait for a specified period of time to acquire the lock.

  5. std::shared_mutex: This is a type of mutex that allows multiple threads to read from a shared resource simultaneously, but only one thread to write to the resource at a time. This can improve performance in situations where multiple threads need to read from a shared resource, but only one thread needs to write to it.

  6. std::shared_timed_mutex: This is a combination of std::shared_mutex and std::timed_mutex. It allows multiple threads to read from a shared resource simultaneously, but only one thread to write to the resource at a time, and also allows threads to wait for a specified period of time to acquire the lock.

相关文章

网友评论

      本文标题:mutex

      本文链接:https://www.haomeiwen.com/subject/mkmvjdtx.html