I started working with BEPU physics this week and must say that this library looks very promising!
My idea is to integrate BEPU with Unity3D (that lacks multithreaded physics and the ability to create spaces) but have stumbled upon problems with deadlocks and would very much appreciate help!
I have found two cases where deadlocks occur:
My first test updates an empty space with multiple threads:
Code: Select all
class Test1
{
static void RunOnce()
{
var looper = new ParallelLooper();
looper.AddThread();
looper.AddThread();
var space = new Space(looper);
space.Update(); //Deadlock here
}
}
Code: Select all
Not Flagged > 139063000 0 Worker Thread
Boolean System.Threading.WaitHandle:WaitOne ()+0x23 at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Threading/WaitHandle.cs:334
Void BEPUphysics.Threading.ParallelLooper:ForLoop (Int32, Int32, Action`1)+0xed at c:\Users\Lorodion\Desktop\bepuphysics-0354fd402025\bepuphysics_0354fd402025\BEPUphysics\Threading\Modified Pool\ParallelLooper.cs:143
Void BEPUphysics.DeactivationManagement.DeactivationManager:UpdateMultithreaded ()+0x1e at c:\Users\Lorodion\Desktop\bepuphysics-0354fd402025\bepuphysics_0354fd402025\BEPUphysics\DeactivationManagement\DeactivationManager.cs:210
Void BEPUphysics.MultithreadedProcessingStage:Update ()+0x25 at c:\Users\Lorodion\Desktop\bepuphysics-0354fd402025\bepuphysics_0354fd402025\BEPUphysics\MultithreadedProcessingStage.cs:83
Void BEPUphysics.Space:DoTimeStep ()+0x1c at c:\Users\Lorodion\Desktop\bepuphysics-0354fd402025\bepuphysics_0354fd402025\BEPUphysics\Space.cs:503
Void BEPUphysics.Space:Update ()+0x1 at c:\Users\Lorodion\Desktop\bepuphysics-0354fd402025\bepuphysics_0354fd402025\BEPUphysics\Space.cs:529
Void Test:Start ()+0x21 at C:\Users\Lorodion\Desktop\BepuTest\Assets\Test\Test.cs:18
Code: Select all
class Test2
{
static void RunOnce()
{
var looper = new ParallelLooper();
looper.AddThread();
var space = new Space(looper);
space.Update();
looper.Dispose(); //Deadlock here
}
}
Code: Select all
Not Flagged > 137490136 0 Worker Thread
Boolean System.Threading.WaitHandle:WaitOne ()+0x23 at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Threading/WaitHandle.cs:334
Void BEPUphysics.Threading.ParallelLooper:RemoveThread ()+0x67 at c:\Users\Lorodion\Desktop\bepuphysics-0354fd402025\bepuphysics_0354fd402025\BEPUphysics\Threading\Modified Pool\ParallelLooper.cs:99
Void BEPUphysics.Threading.ParallelLooper:Dispose ()+0x1f at c:\Users\Lorodion\Desktop\bepuphysics-0354fd402025\bepuphysics_0354fd402025\BEPUphysics\Threading\Modified Pool\ParallelLooper.cs:168
Void Test:Start ()+0x21 at C:\Users\Lorodion\Desktop\BepuTest\Assets\Test\Test.cs:19
I am using BEPU 1.3 compiled with ALLOWUNSAFE (only) for .Net 3.5 in Unity 4.3.1.
I have not been able to reproduce this problem outside of Unity so I'm guessing that their modified Mono CLR is what's causing the trouble.
Still if anyone has any ideas on how to solve this I'm grateful!
/ Jonathan