Functional std::lock, for complex cases
struct A{
std::mutex lock;
unsigned int value;
B* b {nullptr};
}
struct B{
std::mutex lock;
unsigned int value;
A* a {nullptr};
}
struct DataA{
A a;
void swap_A_B_values();
} data_a;
struct DataB{
B b;
void swap_B_A_values();
} data_b;
We want to swap A::value
, with B::value
. Consider that in A
and B
, all values accessed under lock. To swap them, we need to lock both A
and B
. Looks like a job for std::lock
?..