Skip to content

Commit

Permalink
Fixes a dead lock in the effect system
Browse files Browse the repository at this point in the history
The `DynamicEffectInstance` does a blocking wait on the result of the effect system. In there a continuation is created in case the compilation task is not yet finished. In case that continuation got scheduled on the calling thread we ended up in a dead lock.

See also TheFuseLab/VL.Fuse#51
  • Loading branch information
azeno authored and xen2 committed Oct 21, 2021
1 parent 2887398 commit 25710ee
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions sources/engine/Stride.Rendering/Rendering/EffectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,11 @@ public TaskOrResult<Effect> LoadEffect(string effectName, CompilerParameters com

if (bytecode.Task != null && !bytecode.Task.IsCompleted)
{
// Result was async, keep it async
// NOTE: There was some hangs when doing ContinueWith() (note: it might switch from EffectPriorityScheduler to TaskScheduler.Default, maybe something doesn't work well in this case?)
// it seems that TaskContinuationOptions.ExecuteSynchronously is helping in this case (also it will force continuation to execute right away on the thread pool, which is probably better)
// Not sure if the probably totally disappeared (esp. if something does a ContinueWith() externally on that) -- might need further investigation.
// Ensure the continuation is scheduled on the thread pool or we might end up in a dead lock when then calling thread
// is already waiting on the result
var result = bytecode.Task.ContinueWith(
x => CreateEffect(effectName, x.Result, compilerResult),
TaskContinuationOptions.ExecuteSynchronously);
scheduler: TaskScheduler.Default);
return result;
}
else
Expand Down

0 comments on commit 25710ee

Please sign in to comment.