$title 'Test basics of the mutex library' (MTXLIB,SEQ=689) $onText Contributor: Clemens Westphal, November 2015 $offText $call rm -f critical.txt *generate a random mutex ID $eval mtxID round(frac(jnow)*24*60*60*1000) $onEcho > create.gms $funcLibIn mtxlib mtxcclib function Create / mtxlib.Create /; abort$Create(%mtxID%) 'problems creating mutex'; $offEcho $call.checkErrorLevel gams create.gms lo=2 $onEcho > client.gms $funcLibIn mtxlib mtxcclib function Lock / mtxlib.Lock / Unlock / mtxlib.Unlock /; scalar s; s = Lock(%mtxID%); file f /'critical.txt'/; f.ap=1; put f; put "client%number%: a" /; putclose; s = Sleep(1); put f; put "client%number%: b" /; putclose; s = Sleep(1); put f; put "client%number%: c" /; putclose; s = Unlock(%mtxID%); $offEcho $call.Async gams client.gms --number=1 lo=2 lf=log1.txt $eval jh JobHandle $call.checkErrorLevel gams client.gms --number=2 lo=2 lf=log2.txt $label l1 $eval x sleep(1) $eval status JobStatus(%jh%) $if %status% == 1 $goTo l1 $onEcho >criticalExpected1.txt client1: a client1: b client1: c client2: a client2: b client2: c $offEcho $onEcho >criticalExpected2.txt client2: a client2: b client2: c client1: a client1: b client1: c $offEcho $onEcho > delete.gms $funcLibIn mtxlib mtxcclib function Delete / mtxlib.Delete /; abort$Delete(%mtxID%) 'problems deleting mutex'; $offEcho $call.checkErrorLevel gams delete.gms lo=2 $call diff criticalExpected1.txt critical.txt > %system.nullfile% $if errorlevel 1 $call diff criticalExpected2.txt critical.txt > %system.nullfile% $if errorlevel 1 $abort 'critical.txt not as expected' $call rm -f critical.txt