Merge pull request #188 from mlemanczyk/codex/add-unlimited-taskscheduler-subclass
Add unbounded task scheduler for divisor testing
This commit is contained in:
2 files changed
+36
-1
No files matched your search
@@ -253,7 +253,8 @@ public static class MersenneNumberDivisorByDivisorTester
|
|||||||
{
|
{
|
||||||
ParallelOptions options = new()
|
ParallelOptions options = new()
|
||||||
{
|
{
|
||||||
MaxDegreeOfParallelism = workerCount
|
MaxDegreeOfParallelism = workerCount,
|
||||||
|
TaskScheduler = UnboundedTaskScheduler.Instance
|
||||||
};
|
};
|
||||||
|
|
||||||
Parallel.ForEach(filteredPrimes, options, ProcessPrime);
|
Parallel.ForEach(filteredPrimes, options, ProcessPrime);
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PerfectNumbers.Core;
|
||||||
|
|
||||||
|
public sealed class UnboundedTaskScheduler : TaskScheduler
|
||||||
|
{
|
||||||
|
public static UnboundedTaskScheduler Instance { get; } = new();
|
||||||
|
|
||||||
|
private UnboundedTaskScheduler()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int MaximumConcurrencyLevel => int.MaxValue;
|
||||||
|
|
||||||
|
protected override void QueueTask(Task task)
|
||||||
|
{
|
||||||
|
ThreadPool.UnsafeQueueUserWorkItem(static state =>
|
||||||
|
{
|
||||||
|
(UnboundedTaskScheduler Scheduler, Task Task) tuple = ((UnboundedTaskScheduler, Task))state!;
|
||||||
|
tuple.Scheduler.TryExecuteTask(tuple.Task);
|
||||||
|
}, (this, task));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
|
||||||
|
{
|
||||||
|
return TryExecuteTask(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IEnumerable<Task>? GetScheduledTasks()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user