public override bool CanComplete(ThreadState threadState) { // TODO: (much later) support exception here VMValue_objectinst vinst = (VMValue_objectinst)threadState.GetValue(obj); if(vinst.HoldingLockThreadID != threadState.ThreadID) throw new Exception("Calling pulse on a lock we don't possess"); return true; }
public override void Complete(ThreadState threadState) { VMValue dest = threadState.GetValue(destValue); VMValue src = threadState.GetValue(srcValue); dest.CopyFrom(src); dest.IsConcrete = true; if(CheckerConfiguration.DoPrintExecution) { if(dest is VMValue_int32) Console.Write("Committing load of value {0} ",((VMValue_int32)dest).Value); else if(dest is VMValue_double) Console.Write("Committing load of value {0} ",((VMValue_double)dest).Value); else if(dest is VMValue_object) Console.Write("Committing write of {0}", ((VMValue_object)dest).ClassType); else Console.Write("Committing write of non-displayable value"); Console.WriteLine(" from {0} in {1}", sourceInstruction, threadState.CurrentMethod.Name); } }
// A lock action can be completed if the lock is free // or it is currently hold by the same thread public override bool CanComplete(ThreadState threadState) { // A DelayedLock can only be completed if the object instance is not locked // or it is already locked by this thread VMValue_objectinst vinst = (VMValue_objectinst)threadState.GetValue(obj); if((vinst.HoldingLockThreadID == threadState.ThreadID) || (vinst.HoldingLockThreadID == -1)) return true; else return false; }
// In completion stage, the lock action will actually // set the object's lock field to be locked by this thread public override void Complete(ThreadState threadState) { VMValue_objectinst vinst = (VMValue_objectinst)threadState.GetValue(obj); if(vinst.HoldingLockThreadID == -1) { vinst.HoldingLockThreadID = threadState.ThreadID; vinst.HoldingLockCount = nTimes; } else vinst.HoldingLockCount += nTimes; if(CheckerConfiguration.DoPrintExecution) { Console.WriteLine("Commiting Lock in thread " + threadState.CurrentMethod.Name + " on " + obj); } }
public override void Complete(ThreadState threadState) { VMValue_objectinst vinst = (VMValue_objectinst)threadState.GetValue(obj); if(vinst.HoldingLockThreadID == threadState.ThreadID) { vinst.HoldingLockCount--; if(vinst.HoldingLockCount == 0) vinst.HoldingLockThreadID = -1; } else { // If we unlock a lock that // this thread does not possess, the instruction // executes normally but has no effect } if(CheckerConfiguration.DoPrintExecution) { Console.WriteLine("Commiting Unlock in thread " + threadState.CurrentMethod.Name + " on " + obj); } }