A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Stucuk » Fri Aug 27, 2010 6:34 pm
Im wondering if the following could cause 2 threads to Deadlock. Thread B calls the NewtonUpdate every 1/60th of a second. When there is a callback from Newton its syncronised to Thread A. My concern is if Thread A tries to do something with Newton while Thread B is doing the NewtonUpdate that Thread A would then be Waiting for Thread B to finish. So if a callback is called, then Thread B would wait for Thread A, which in Turn is waiting on Thread B.
Thread B
- Code: Select all
Repeat
Lock;
FTimer.Refresh;
UpdateWorld(FTimer.FrameTime); //We start the NewtonUpdate
...
Thread A
- Code: Select all
NewtonThread.Lock; //Waits for Thread B as its currently Locked.
...
Newton Sends Callback to Thread B Which then Tries to Sync with Thread A
- Code: Select all
procedure TNewtonThread.PhysicsSetTransform(const body : PNewtonBody; const matrix : TMatrix; Forwardto : Pointer);
begin
FBody := Body;
FMatrix := Matrix;
FForwardTo := ForwardTo;
FForwardType := ftPhysicsSetTransform;
Synchronize(ForwardProc); //Deadlock?
end;
If im correct ill have to do it a more annoying way where every Class that can have physics and be rendered will have to have Critical Sections.
-

Stucuk
-
- Posts: 801
- Joined: Sat Mar 12, 2005 3:54 pm
- Location: Scotland
-
by Julio Jerez » Fri Aug 27, 2010 8:06 pm
do not wrroied abpu thread locking the engien try to take case of tha intenally.
whe you get a callback, the only time you will have to lock is if teh callback write to data that is part of a different callback.
-
Julio Jerez
- Moderator

-
- Posts: 12452
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Stucuk » Fri Aug 27, 2010 8:51 pm
The locks arn't Newton's. There custom Critical Sections ( EnterCriticalSection() ) to stop the Main Thread from trying to access Newton while its being updated by the NewtonThread Thread.
-

Stucuk
-
- Posts: 801
- Joined: Sat Mar 12, 2005 3:54 pm
- Location: Scotland
-
by Julio Jerez » Fri Aug 27, 2010 10:23 pm
critical section do not intefate with each other. onless they sue the same handle.
you cans lock teh tread and notion will pass the critical section inlcuding Netwon.
you should be ok.
-
Julio Jerez
- Moderator

-
- Posts: 12452
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Stucuk » Sat Aug 28, 2010 12:00 pm
They are the same Handle, Both locks in the sample code use the same Critical Section. Im not using Newton's own Critical Sections. What newton does isn't at question, its my bad concept of putting newton in a separate thread with the least amount of critical sections thats at question.
-

Stucuk
-
- Posts: 801
- Joined: Sat Mar 12, 2005 3:54 pm
- Location: Scotland
-
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 54 guests