Hi,
I have an application which needs to access data from another thread but I'm not sure how to handle this. I am explaining this in terms of physics objects which my application has but there other cases like this as well so its not a physics problem.
Basically I have a physics object class which is part of the private implementation and a physics object user class which acts a wrapper to the private implementation. The user only sees the wrapper class and does not know about the existence of the internal class or what it does. The internal class has some functions which compute its state, such as gravity acceleration mass etc. The problem is that I want the user to be able to query those variables. Some variables are constant (eg: mass) however some of them are dynamic and need to be computed every time the simulation updates on its own thread (eg: acceleration). This computation can only be done when the physics thread is allowed to run, but the user can potentially create and call functions on the wrapper class from anywhere and these should not cause any problems. This works when the user is trying to set data as the wrapper class buffers it up until the thread is allowed to run, but I am not sure how the user can get the data at any time ?
eg:
---public---
---private---Code:class PhysicsObjectUser { public: float GetGravity(); //can be called at any time from the client side application, how do i handle this ? void ApplyForce(float amt);//this is buffered up until the physics thread is entered and then the corresponding function in the internal interface is called. }
How can I give the user its data instantly without having them worry about threading issues. I am open to redesigning my interface so if there are existing solutions to this kind of problem, let me know. I was thinking of caching the variables in the wrapper class and then fill them up every time the physics step runs but there are too many variables and this will increase the size of the wrapper class significantly and perhaps decrease performance.Code:class PhysicsObjectInternal { public: float ComputeGravity(); //can only be called when the physics thread is entered }
Any ideas ?
Thanks!



LinkBack URL
About LinkBacks


