/// <summary> /// Creates an event thread. /// </summary> /// <param name="name">The name of the thread.</param> /// <param name="priority">The priority of the thread.</param> protected NSFThread(NSFString name, int priority) : base(name) { TerminationStatus = NSFThreadTerminationStatus.ThreadReady; OSThread = NSFOSThread.create(Name, new NSFVoidAction <NSFContext>(threadEntry), priority); NSFEnvironment.addThread(this); }
/// <summary> /// Terminates the thread by causing the execution method to return. /// </summary> /// <param name="waitForTerminated">Flag indicating if the method should wait until the thread is terminated (true), or if it should return immediately (false).</param> /// <remarks> /// This method is useful to guarantee that a thread is no longer active, so that it can be garbage collected. /// If the waitForTerminated flag is set true, this method must not be called from its thread of execution. /// </remarks> public virtual void terminate(bool waitForTerminated) { lock (threadMutex) { if (TerminationStatus != NSFThreadTerminationStatus.ThreadTerminated) { TerminationStatus = NSFThreadTerminationStatus.ThreadTerminating; } } if (waitForTerminated) { for (uint i = 0; i < TerminationTimeout; i += TerminationSleepTime) { if (TerminationStatus == NSFThreadTerminationStatus.ThreadTerminated) { return; } NSFOSThread.sleep(TerminationSleepTime); } handleException(new Exception("Thread was unable to terminate")); } }
public void terminate(bool waitForTerminated) { if (!isTopStateMachine()) { TopStateMachine.terminate(waitForTerminated); return; } queueEvent(terminateEvent); if (waitForTerminated) { for (uint i = 0; i < TerminationTimeout; i += TerminationSleepTime) { if (TerminationStatus == NSFEventHandlerTerminationStatus.EventHandlerTerminated) { return; } NSFOSThread.sleep(TerminationSleepTime); } handleException(new Exception("State machine was unable to terminate")); } }
public ContextSwitchTest(String name) { Name = name; signal1 = NSFOSSignal.create("Signal1"); signal2 = NSFOSSignal.create("Signal2"); thread1 = NSFOSThread.create("Thread1", thread1Loop, NSFOSThread.HighestPriority); thread2 = NSFOSThread.create("Thread2", thread2Loop, NSFOSThread.HighestPriority); }