Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Situation where mutexes are necessary?

Tags:

c++

mutex

Can someone help me out with example of a situation in which absence of mutexes "definetely" leads to incorrect result.

I need this so that I could test my mutex implementation.

-- Neeraj

like image 636
sud03r Avatar asked Dec 22 '22 01:12

sud03r


1 Answers

Consider any correct code that uses mutexes for synchronization. By removing the locking, you will introduce new (possibly incorrect) behaviors (executions) to the program. However, the new code will still contain all of the old behaviors, therefore there will always be at least one execution that will yield a correct result. Hence, what you're asking for is impossible.

like image 124
avakar Avatar answered Jan 04 '23 01:01

avakar