Bepu for Windows Store apps

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
thiago
Posts: 22
Joined: Sat Oct 16, 2010 10:32 pm

Bepu for Windows Store apps

Post by thiago »

Hi,

i was trying to compile Bepu for .Net Windows Store apps but i got some troubles.
In this platform, we dont have the threads the way we usually have in .Net (async paragim ...) so lots of errors appeared on WorkerThread and ParallelLoopWorker

is there a plan to port Bepu (only the WorkerThread/ParallelLoopWorker classes actually) to work with .Net Windows Store ? (i was using Mono to replace XNA in Windows 8 btw)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Bepu for Windows Store apps

Post by Norbo »

I haven't quite decided how to manage the windows store yet. In the interim, it's easy enough to create a custom thread manager using whatever thread pools are available on a given platform.

Delete any of the IThreadManager implementations which do not compile and create a custom one. As an example, check out the ThreadManagerTPL uses the Task Parallel Library as a thread pool. There's not much to it; the only important function is the ForLoop. For a TPL-based pool, that boils down to a call to the Parallel.For function.

In fact, you may just want to delete the IThreadManager's requirement for AddThread, RemoveThread, EnqueueTask, and WaitForTaskCompletion. The engine itself never directly calls any of those: AddThread/RemoveThread are for external use, and EnqueueTask/WaitForTaskCompletion are there strictly for legacy reasons.
thiago
Posts: 22
Joined: Sat Oct 16, 2010 10:32 pm

Re: Bepu for Windows Store apps

Post by thiago »

Another problem.
You used SpinLock for very small waiting periods.
But the Thread.SpinWait was gone also ....
i changed this to System.Threading.Tasks.Task.Delay(0); (same as Thread.Sleep(0) )
but this implies in a context switch ....

you, that know the macro architecture of bepu =P, think that this change will hurt too much the performance ?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Bepu for Windows Store apps

Post by Norbo »

It could very well hurt performance; that lock is used for sections which are held for extremely brief periods (sometimes a matter of nanoseconds). Some other busywait style replacement for Thread.SpinWait would be better. Perhaps the SpinWait structure, or an actual busyloop (though you'd have to do it in a way that doesn't get compiled out!).

I'd assume the .NET SpinLock structure is still available on the Windows Store, too. Its performance should be similar to the BEPU version, though you'd have to refactor some bits due to the different function signatures.
thiago
Posts: 22
Joined: Sat Oct 16, 2010 10:32 pm

Re: Bepu for Windows Store apps

Post by thiago »

i will go for busy loop for now.
i searched and there is no SpinLock in >net for Windows Store apps

thanks
Phippu
Posts: 24
Joined: Fri Jun 03, 2011 3:39 pm

Re: Bepu for Windows Store apps

Post by Phippu »

If done if this way (seems to work fine...):

Code: Select all

       private static ManualResetEvent resetEvent = new ManualResetEvent(false);

        private static void Sleep(int ms)
        {
            resetEvent.WaitOne(ms);
        }

        internal void WaitBriefly(ref int attempt)
        {
            if (attempt == SleepInterval)
            {
#if WINDOWS
                Thread.Yield();
#elif NETFX_CORE
                Sleep(0);
#else
                Thread.Sleep(0);
#endif
                //TODO: Thread.Yield on windows?
                //Check multithreaded bookmarks performance conscious
                //and .netspinlock
                attempt -= SleepInterval;
            }
            else
            {
#if NETFX_CORE
                //Thread.SpinWait(Math.Min(3 << attempt, MaximumSpinWait));
                System.Threading.SpinWait.SpinUntil(() => true, Math.Min(3 << attempt, MaximumSpinWait));
#else
                Thread.SpinWait(Math.Min(3 << attempt, MaximumSpinWait));
#endif
            }
        }
    }
Post Reply