Bobby Smith
Bobby Smith

Reputation: 11

Deadlocking occurring in Mutex code?

I'm trying to figure out whats wrong with this segment of code? I've been studying it for a while and I still cannot see any dead-lock if there is one. Any hints would be greatly appreciated!

Mutex mA;
Mutex mB;

Take(mA);
Take(mB);

DoSomething(); 

Release(mA); 
Release(mB);

Upvotes: 1

Views: 80

Answers (1)

Mats Petersson
Mats Petersson

Reputation: 129524

This code on it's own will not cause a problem. But if you have code that uses the reverse Take(mB); Take(mA); somewhere else, you can get a deadlock.

Upvotes: 2

Related Questions