1

Topic: In what cases two are used at once mutex?

Feeblly I understand multi-threaded programming. Prompt, please, for what happens it is necessary to use at once two mutex? class ProtectedResource {std:: mutext m_mutex1; std:: mutext m_mutex1; Resource m_resource; public: void accessSharedResource () {std:: lock_guard <mutex> locker1 (m_mutex1); std:: lock_guard <mutex> locker2 (m_mutex2);//access m_resource}} I.e. happens that one mutex not enough? In what cases?

2

Re: In what cases two are used at once mutex?

Hello, Maxim Rogozhin, you wrote: > Feeblly I understand multi-threaded programming. Prompt, please, for what happens it is necessary to use at once two mutex? When it is required to address to simultaneously two securable data. Generally, it is better such to avoid, since the different order of capture  - a method to receive deadlock.

3

Re: In what cases two are used at once mutex?

Hello, Alexander G, you wrote: AG> When it is required to address to simultaneously two securable data. Thanks. I.e. I turn out a wrong code sample resulted? At me only one resource m_resource - in such cases two mutex are never necessary, so?

4

Re: In what cases two are used at once mutex?

Hello, Alexander G, you wrote: AG> Hello, Maxim Rogozhin, you wrote: >> Feeblly I understand multi-threaded programming. Prompt, please, for what happens it is necessary to use at once two mutex? AG> When it is required to address to simultaneously two securable data. AG> generally, it is better such to avoid, since the different order of capture  - a method to receive deadlock. As addition - in with ++ 17 in order to avoid this miracle it is entered std:: scoped_lock

5

Re: In what cases two are used at once mutex?

Hello, Maxim Rogozhin, you wrote: > At me only one resource m_resource - in such cases two mutex are never necessary, so? Yes.

6

Re: In what cases two are used at once mutex?

Hello, rumit7, you wrote: R> as addition - in with ++ 17 in order to avoid this miracle it is entered std:: scoped_lock In With ++ 11 same becomes with the help adopt_lock. std:: lock (e1.m, e2.m); std:: lock_guard <std:: mutex> lk1 (e1.m, std:: adopt_lock); std:: lock_guard <std:: mutex> lk2 (e2.m, std:: adopt_lock);