Skip to content

zmq::condition_variable_t needs cleanup #3404

@sigiesec

Description

@sigiesec

zmq::condition_variable_t needs some cleanup:

  • the implementation under _WIN32_WINNT < 0x0600 && !_SUPPORT_CONDITION_VARIABLE is unusable, it asserts in the constructor. since this is detected at compile-time, all depending functionality (i.e. thread-safe sockets), should also be disabled at compile-time
  • the implementation under _SUPPORT_CONDITION_VARIABLE && (defined(ZMQ_HAVE_WINDOWS_TARGET_XP) || _WIN32_WINNT < 0x0600) uses a second mutex for syntactic reasons: since zmq::condition_variable_t::wait accepts a zmq::mutex_t, but std::condition_variable::wait requires a std::unique_lockstd::mutex, this overhead is required. This could be resolved by
    • using this implementation iff mutex_t (or maybe a specific cv_mutex_t, if std:.mutex should not be used in other cases) is std::mutex
    • define zmq::scoped_lock_t as std::unique_lock<mutex_t> in this case
    • change the parameter of zmq::condition_variable_t::wait from zmq::mutex_t to zmq::scoped_lock_t

As pointed out in #3373 (comment), the current implementation in the second case seems to have a race condition related to handling the two mutexes. This would be automatically resolved by the improvements suggested above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions