/// <summary> /// Creates a micro thread out of the specified function and schedules it as last micro thread to run in this scheduler. /// Note that in case of multithreaded scheduling, it might start before this function returns. /// </summary> /// <param name="microThreadFunction">The function to create a micro thread from.</param> /// <param name="flags">The flags.</param> /// <returns>A micro thread.</returns> public MicroThread Add(Func <Task> microThreadFunction, MicroThreadFlags flags = MicroThreadFlags.None) { var microThread = new MicroThread(this, flags); microThread.Start(microThreadFunction); return(microThread); }
public MicroThread(Scheduler scheduler, MicroThreadFlags flags = MicroThreadFlags.None) { Id = Interlocked.Increment(ref globalCounterId); Scheduler = scheduler; ScheduledLinkedListNode = new PriorityQueueNode <MicroThread>(this); AllLinkedListNode = new LinkedListNode <MicroThread>(this); ScheduleMode = ScheduleMode.Last; Flags = flags; Tags = new PropertyContainer(this); }
public MicroThread(Scheduler scheduler, MicroThreadFlags flags = MicroThreadFlags.None) { Id = Interlocked.Increment(ref globalCounterId); Scheduler = scheduler; ScheduledLinkedListNode = new PriorityQueueNode <SchedulerEntry>(new SchedulerEntry(this)); AllLinkedListNode = new LinkedListNode <MicroThread>(this); ScheduleMode = ScheduleMode.Last; Flags = flags; Tags = new PropertyContainer(this); cancellationTokenSource = new CancellationTokenSource(); }
public MicroThread(Scheduler scheduler, MicroThreadFlags flags = MicroThreadFlags.None) { Id = Interlocked.Increment(ref globalCounterId); Scheduler = scheduler; ScheduledLinkedListNode = new PriorityQueueNode<SchedulerEntry>(new SchedulerEntry(this)); AllLinkedListNode = new LinkedListNode<MicroThread>(this); ScheduleMode = ScheduleMode.Last; Flags = flags; Tags = new PropertyContainer(this); cancellationTokenSource = new CancellationTokenSource(); }
protected MicroThread[] TestBase(string testName, BaseTests baseTests, Func <Action, Task> asyncFunction, int parallelCount, MicroThreadFlags flags = MicroThreadFlags.None) { var scheduler = new Scheduler(); int completed = 0; var microThreads = new MicroThread[parallelCount]; // Run two microthreads at the same time for (int i = 0; i < parallelCount; ++i) { microThreads[i] = scheduler.Add(() => asyncFunction(() => { Interlocked.Increment(ref completed); CheckStackForSchedulerStep(); }), flags); } // Simulation of main loop for (int i = 0; i < 1000 && scheduler.MicroThreads.Count() > 0; ++i) { baseTests.SharedCounter = i; scheduler.Run(); Thread.Sleep(10); } // Check both microthreads completed Assert.That(completed, Is.EqualTo(parallelCount)); return(microThreads); }
/// <summary> /// Creates a micro thread out of the specified function and schedules it as last micro thread to run in this scheduler. /// Note that in case of multithreaded scheduling, it might start before this function returns. /// </summary> /// <param name="microThreadFunction">The function to create a micro thread from.</param> /// <param name="flags">The flags.</param> /// <returns>A micro thread.</returns> public MicroThread Add(Func<Task> microThreadFunction, MicroThreadFlags flags = MicroThreadFlags.None) { var microThread = new MicroThread(this, flags); microThread.Start(microThreadFunction); return microThread; }