Is there a simple time-locking algorithm that avoids deadlocks when multiple mutual errors occur?

The C ++ 0x thread library or Boost.thread defines a non-member variational template function that blocks all mutex at once, which helps to avoid a deadlock.

template <class L1, class L2, class... L3> 
void lock(L1&, L2&, L3&...);

The same can be applied to the Variadic function of the non-member try_lock_until template, which locks all mutexes until the specified time is reached, which will help to avoid blocking as a lock (...).

template <class Clock, class Duration,
          class L1, class L2, class... L3> 
void try_lock_until(
          const chrono::time_point<Clock,Duration>& abs_time, 
          L1&, L2&, L3&...);

I have an implementation that follows the same pattern as the Boost boost :: lock (...) function. But it is rather difficult.

How can I skip something obvious, I would like to know if:

Is there a simple time-locking algorithm to prevent deadlock with multiple mutexes?

, Boost?

P.S. , .


:

  • , , std:: lock (...) .
  • std:: lock (...) . , std:: lock (l1, l2) std:: lock (l2, l1). , .
+3
2

( ) , , , , . ?

+4

, , , - . . , , . , .

0

Source: https://habr.com/ru/post/1743712/


All Articles