[ODE] multihreading and ODE
cesar pachon
cesarpachon at yahoo.es
Mon Jan 24 19:52:52 MST 2005
ok, I am going to try with a single thread, and some
kind of dt accumulator to emulate a fixed-frame rate.
I am using SDL, and it provides a abstraction for
mutexes in any OS, but I never had worked with them.
About the vibration, I guess it happens when the paint
thread reads position info and in the same time the
ODE thread is updating the objects.
a lot of thanks for your help!
--- Chunky Kibbles <chunky at icculus.org> escribió:
> On Mon, Jan 24, 2005 at 02:45:26PM +0100, cesar
> pachon wrote:
> > hello! I put a separate thread (timer) for
> > fixed-stepping ODE, and a Main thread with
> > update-paint code.. the problem is that
> periodically
> > my car (a simple car simulation) vibrates. it
> quicky
> > becomes stable, but graphically looks bad. my code
> is:
> >
> >
> > timer_func(){
> > stepping_ode = true;
> > dWorldQuickStep (dWorldID, fixedstepsize);
> > stepping_ode = false;
> > }
> > this method runs a 30 fps. My Update and Paint
> thread
> > runs at 120 fps (no constant rate) and I check the
> > flag:
> > update(){
> > //calculate actual framerate..
> > if(!stepping_ode){
> > //query ODE and update graphic objects.. pos
> and
> > rot.
> > }
> > paint();
> > }
> > my question is.. is something bad with the flag?
> do I
> > need sync also the reading method? If I do that,
> it
> > would affect the fixed framerate of ODE stepping
> > function?
> > thanks by the help!
>
> Yes, there's something bad with the flag. Consider
> the case where
> stepping_ode is false.
> if(!stepping_ode){
> //query ODE and update graphic objects.. pos and
> rot.
> }
>
> This will run. Now, if you enter this function and
> the other thread
> executes for a while...
> timer_func(){
> stepping_ode = true;
> dWorldQuickStep (dWorldID, fixedstepsize);
> stepping_ode = false;
> }
>
> It's possible for dWorldQuickStep to start running,
> even thought you're
> updating the screen. This is, though, unlikely to be
> a real problem [you
> need to fix it anyways].
>
> If you're on a *nix alike, use a pthread_mutex:
>
>
> pthread_mutex_t stepping_mut;
> pthread_mutex_init(&stepping_mut, NULL);
>
> timer_func(){
> pthread_mutex_lock(&stepping_mut);
> dWorldQuickStep (dWorldID, fixedstepsize);
> pthread_mutex_unlock(&stepping_mut);
> }
>
> pthread_mutex_lock(&stepping_mut);
> // query ODE and update graphic objects.. pos and
> rot.
> pthread_mutex_unlock(&stepping_mut);
>
>
>
> If you're on anything that doesn't support posix
> threads, I don't know
> how to help you.
>
> In practice, you should consider threads the wrong
> solution to the
> problem [if you didn't know about mutexes, they're
> DEFINITELY the wrong
> solution to the problem]. I'd urge you to do the
> above in a single
> thread.
>
> I suspect that this isn't real real problem, by the
> way. It's more
> likely something else happening, but I've no idea
> what that might be.
> Check that your bodies are being disabled correctly.
>
> Gary (-;
>
______________________________________________
Renovamos el Correo Yahoo!: ¡250 MB GRATIS!
Nuevos servicios, más seguridad
http://correo.yahoo.es
More information about the ODE
mailing list