multiply_mutex - Melnytskyi/fast_task GitHub Wiki

Declaration

    struct multiply_mutex {
        std::vector<mutex_unify> mu;
        multiply_mutex(const std::initializer_list<mutex_unify>& muts);
        void lock();
        bool try_lock();
        bool try_lock_for(size_t milliseconds);
        bool try_lock_until(std::chrono::high_resolution_clock::time_point time_point);
        void unlock();
    };

This struct created to safely manage multiply mutexes in specified order.

The try_lock, try_lock_* functions unlocks every locked mutex in reversed order if there an unsuccessful attempt. Also unlock will unlock in reversed order.

DOES NOT UNLOCKS ON DESTRUCTION

USE ONLY IN ONE THREAD

Usage

std::mutex some_mutex, some_mutex2;
fast_task::multiply_mutex hold{some_mutex, some_mutex2};
{
   std::lock_guard guard(hold);
   //...
}