folly::acquireLocked

Acquire locks for multiple Synchronized<T> objects, in a deadlock-safe manner.

Synopsis

Declared in <folly/Synchronized.h>

template<
    class Sync1,
    class Sync2>
std::tuple</* implementation-defined */, /* implementation-defined */>
acquireLocked(
    Sync1& l1,
    Sync2& l2);

Description

The locks are acquired in order from lowest address to highest address. (Note that this is not necessarily the same algorithm used by std::lock().) For parameters that are const and support shared locks, a read lock is acquired. Otherwise an exclusive lock is acquired.

use lock() with folly::wlock(), folly::rlock() and folly::ulock() for arbitrary locking without causing a deadlock (as much as possible), with the same effects as std::lock()

Return Value

A tuple of locked pointers, one per object.

Parameters

NameDescription
l1The first object to lock.
l2The second object to lock.