Consider:
do par
thread1:
do
print "begin";
x:=x+1;
print x;
end; // thread1
thread2:
do
x:=10;
end; // thread2
end par;
//Insert MInitialize(m), MRequest(m)'s, and MRelease(m)'s for a mutex m into the above code so that it is guaranteed to print:
begin
11
//Don't otherwise change the existing code - only insert the above function calls. Hint: A thread may release a mutex without having requesting it. You don't need to translate and run this.
I've spent so many hours and asked so many people.. lol.. someone know this please help, thanks!
Ah, there it is.
Line 11: Don't unlock a mutex in a thread when that thread hasn't locked it.
As a rule of thumb, abs((number of locks)-(number of unlocks))<=(how many problems you have)
Just add a set of lock-unlock around line 14 and you should be fine.