use System.Threading class ThreadExample var _maxSeconds = 0.2f var _start as DateTime def run _start = DateTime.now sw = StringWriter() print to sw t = Thread(ref .writeB) t.start lock this while not .isFinished print 'a' stop t.join output = sw.toString # trace output if 'a' in output, assert 'b' not in output if 'b' in output, assert 'a' not in output def writeB lock this while not .isFinished print 'b' stop get isFinished as bool return DateTime.now.subtract(_start).totalSeconds >= _maxSeconds def main ThreadExample().run