# How can I save state from script in a multithreaded engine?

We are building a multithreaded game engine and we've encountered some problems as described below.

Ok, well, all the task schedule part work well, but here's the problem:

For the simplest, I'll take Camera as an example:

local oldPos = camera:getPosition()  -- ( 0, 0, 0 )
camera:setPosition( 1, 1, 1 )        -- Won't work now, cuz the render thread will process the task at the beginning of the next frame
local newPos = camera:getPosition()  -- Still ( 0, 0, 0 )


So that's the problem: If you intend to change a property of an object in another thread, you have to wait until that thread process this property-changing message. As a result, what you get from the object is still the information in the last frame.

So, is there a way to solve this problem? Or are we build the task schedule part in a wrong way? Thanks for your answers :)

• I know it's ok that we store those properties and states at the C++ side, but you know that is a HUGE amount of work. I'm looking for some solution that is easier to do. – Peter Ren Jun 5 '12 at 8:10

If objects are in separate threads and you're treating threads as completely separate processes, the objects must obey one of 2 restrictions:

1. The objects in Thread 1 can work with old data for the objects in Thread 2 (so it doesn't matter that the changed position is 1 frame out of date)