Is it possible to implement C++11 mutex concept for use by std::condition_variable?

Emily L.

I find that the std::mutex implementation in Visual Studio 2013 is too slow. It uses a heavy weight mutex to assure that synchronization can be achieved even between processes which is all fine and dandy; Unless you're not talking to other processes and could really use that extra speed that CRITICAL_SECTION with it's spin-lock offers on Win32.

I tried to implement a fast_recursive_mutex that adheres to the C++11 mutex concept and that fulfills all obligations according to spec. In all senses, it's a drop-in replacement for std::mutex as long as you're not synchronizing between processes.

It works great with std::lock_guard and std::unique_lock. However I encounter problems when trying to use it with std::condition_variable because std::condition_variable::wait(std::unique_lock<std::mutex>&) doesn't admit my fast_recursive_mutex due to the hard coded use of std::mutex.

So my questions are:

  1. Why does wait() not admit another mutex type than std::mutex?
  2. Is there something I can do about it? (Short of re-implementing condition_variable).
Piotr Skotnicki

You can use std::condition_variable_any for any lockable type.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

std::condition_variable why does it need a std::mutex

From Dev

std::condition_variable why does it need a std::mutex

From Dev

Stopping C++ 11 std::threads waiting on a std::condition_variable

From Dev

Stopping C++ 11 std::threads waiting on a std::condition_variable

From Dev

Is it possible to use Firebase to implement a distributed mutex?

From Dev

C++11 could not convert std::condition_variable::wait from 'void' to 'bool'

From Dev

C++11 std::condition_variable - notify_one() not behaving as expected?

From Dev

Gtest with C++11 std::condition_variable implies valgrind errors

From Dev

Gtest with C++11 std::condition_variable implies valgrind errors

From Dev

C++ condition_variable mutex lock issue

From Dev

C Confused on how to initialize and implement a pthread mutex and condition variable

From Dev

C Confused on how to initialize and implement a pthread mutex and condition variable

From Dev

Why do both the notify and wait function of a std::condition_variable need a locked mutex

From Dev

C++ threads: cannot unlock mutex in array after condition_variable wait

From Dev

C++ threads: cannot unlock mutex in array after condition_variable wait

From Dev

Exception handling for <mutex> and <condition_variable>

From Dev

using CONDITION_VARIABLE with mutex HANDLE

From Dev

Why does C++20 std::condition_variable not support std::stop_token?

From Dev

Why does C++20 std::condition_variable not support std::stop_token?

From Dev

It is possible to use array reduce concept from swift in objective c?

From Dev

C++11 pass std::unique_lock<std::mutex> to lambda

From Dev

C++11 pass std::unique_lock<std::mutex> to lambda

From Dev

C++ pimpI mutex preventing usage of std::condicition_variable

From Dev

Map of mutex c++11

From Dev

Leads a C++11 std::mutex lock the blocked thread into a passive wait state?

From Dev

std::condition_variable without a lock

From Dev

Using std::condition_variable with atomic<bool>

From Dev

Why is there no wait function for condition_variable which does not relock the mutex

From Dev

condition_variable without mutex in a lock-free implementation

Related Related

  1. 1

    std::condition_variable why does it need a std::mutex

  2. 2

    std::condition_variable why does it need a std::mutex

  3. 3

    Stopping C++ 11 std::threads waiting on a std::condition_variable

  4. 4

    Stopping C++ 11 std::threads waiting on a std::condition_variable

  5. 5

    Is it possible to use Firebase to implement a distributed mutex?

  6. 6

    C++11 could not convert std::condition_variable::wait from 'void' to 'bool'

  7. 7

    C++11 std::condition_variable - notify_one() not behaving as expected?

  8. 8

    Gtest with C++11 std::condition_variable implies valgrind errors

  9. 9

    Gtest with C++11 std::condition_variable implies valgrind errors

  10. 10

    C++ condition_variable mutex lock issue

  11. 11

    C Confused on how to initialize and implement a pthread mutex and condition variable

  12. 12

    C Confused on how to initialize and implement a pthread mutex and condition variable

  13. 13

    Why do both the notify and wait function of a std::condition_variable need a locked mutex

  14. 14

    C++ threads: cannot unlock mutex in array after condition_variable wait

  15. 15

    C++ threads: cannot unlock mutex in array after condition_variable wait

  16. 16

    Exception handling for <mutex> and <condition_variable>

  17. 17

    using CONDITION_VARIABLE with mutex HANDLE

  18. 18

    Why does C++20 std::condition_variable not support std::stop_token?

  19. 19

    Why does C++20 std::condition_variable not support std::stop_token?

  20. 20

    It is possible to use array reduce concept from swift in objective c?

  21. 21

    C++11 pass std::unique_lock<std::mutex> to lambda

  22. 22

    C++11 pass std::unique_lock<std::mutex> to lambda

  23. 23

    C++ pimpI mutex preventing usage of std::condicition_variable

  24. 24

    Map of mutex c++11

  25. 25

    Leads a C++11 std::mutex lock the blocked thread into a passive wait state?

  26. 26

    std::condition_variable without a lock

  27. 27

    Using std::condition_variable with atomic<bool>

  28. 28

    Why is there no wait function for condition_variable which does not relock the mutex

  29. 29

    condition_variable without mutex in a lock-free implementation

HotTag

Archive