Skip to content

Commit

Permalink
Allow task scheduler parameter to ExecutionEngine (#794)
Browse files Browse the repository at this point in the history
This allows the creator of an `ExecutionEngine` to pass in a
`CustomStackSizePoolTaskScheduler` so that the scheduler can be shared
between different instantiations of an execution engine. We normally
want only one scheduler per machine, but sometimes want multiple
execution engines.
  • Loading branch information
atomb authored Oct 10, 2023
1 parent 1dd882f commit c59e3cb
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Source/ExecutionEngine/ExecutionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,21 @@ public static int AutoRequestId(string id) {
static readonly CacheItemPolicy policy = new CacheItemPolicy
{ SlidingExpiration = new TimeSpan(0, 10, 0), Priority = CacheItemPriority.Default };

public ExecutionEngine(ExecutionEngineOptions options, VerificationResultCache cache) {
private const int stackSize = 16 * 1024 * 1024;

public ExecutionEngine(ExecutionEngineOptions options, VerificationResultCache cache)
: this(options, cache, CustomStackSizePoolTaskScheduler.Create(stackSize, options.VcsCores))
{
taskSchedulerCreatedLocally = true;
}

public ExecutionEngine(ExecutionEngineOptions options, VerificationResultCache cache, CustomStackSizePoolTaskScheduler scheduler) {
Options = options;
Cache = cache;
checkerPool = new CheckerPool(options);
verifyImplementationSemaphore = new SemaphoreSlim(Options.VcsCores);
largeThreadScheduler = CustomStackSizePoolTaskScheduler.Create(16 * 1024 * 1024, Options.VcsCores);

largeThreadScheduler = scheduler;
largeThreadTaskFactory = new(CancellationToken.None, TaskCreationOptions.None, TaskContinuationOptions.None, largeThreadScheduler);
}

Expand All @@ -89,6 +97,7 @@ static readonly ConcurrentDictionary<string, TimeSpan>
new ConcurrentDictionary<string, CancellationTokenSource>();

private readonly CustomStackSizePoolTaskScheduler largeThreadScheduler;
private bool taskSchedulerCreatedLocally = false;

public async Task<bool> ProcessFiles(TextWriter output, IList<string> fileNames, bool lookForSnapshots = true,
string programId = null) {
Expand Down Expand Up @@ -1385,7 +1394,9 @@ private static void WriteErrorInformationToXmlSink(XmlSink sink, ErrorInformatio
public void Dispose()
{
checkerPool.Dispose();
largeThreadScheduler.Dispose();
if (taskSchedulerCreatedLocally) {
largeThreadScheduler.Dispose();
}
}
}
}

0 comments on commit c59e3cb

Please sign in to comment.