Jump to content
Sign in to follow this  
Scrocco88

PublicVariable and Data consistency

Recommended Posts

Imagine i have 2 scripts that can be executed at the same time, using the same variable (on different unit event handler for example).

Someting like that:

var = var +1;
publicVariable "var";

Can i be sure data will be updated correctly and will always be consistent?

Edited by Scrocco88

Share this post


Link to post
Share on other sites

Not easily done, no.

The way to make sure you have it acting fully consistent is to do the variable updates on the same machine (ex. Server).

Share this post


Link to post
Share on other sites

ok... but if i have something like:

First event:

if(isServer) then {

   ....
   end_of_first_block
}

Second event:

if(isServer) then {
   start_of_second_block
   ....

}

and the 2 events fires "at the same time", is it SURE they are execute sequentially? (or they can overlap?)

end_of_first_block is executed before start_of_second_block?

Share this post


Link to post
Share on other sites

They will execute sequentially if they're both in a single thread, i.e. running from a single .sqf. You can run multiple scripts in parallel on a single machine, and use globalVariables on that machine to do this, but multiple scripts on multiple machines have to wait for the engine to get around to doing it's publicVariable updates, which I don't believe have any guarantee of speed.

Edit: Global variables on a single machine are, erm, global, so do not need to be broadcast whatsoever with publicVariable.

Edit 2: Was thinking about this, and perhaps an approach might be to add a global variable that, for instance, will only let the first thread go into its loop if set to 0, and only let the second thread do it if set to 1 <enforce with waitUntil>, and then have each thread adjust that variable to allow the other thread to continue when the time is right. I don't exactly know, I have never done much concurrency to begin with and certainly not on the RV engine ;)

Edited by dwringer

Share this post


Link to post
Share on other sites

Ok... non that easy indeed... and i dont know how to find any multi-thread or concurrency documentation about game engine.

Thank you very much. :)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×