Hi everyone,
I am writing a server and I need to generate chunks of the world and access them in other threads. The initialization may take a while (seconds), but I need the other threads to be faster than that (basically realtime).
My idea is to use multiple mutexes per chunk, an InitMutex and a ModifyMutex.
When initializing (pseudocode):
Lock InitMutex;
Initialize the chunk;
Lock ModifyMutex;
Set status "initialized";
Unlock both mutexes;
When reading/modifying:
Lock ModifyMutex;
If status is "initialized":
Perform operations on chunk data;
Unlock ModifyMutex;
Does this work? Will the thread that only locks the ModifyMutex see the data written by the initialization thread?
In the standard it says:
QuoteAll lock and unlock operations on the mutex follow a single total order, with all visible effects synchronized between the lock operations and previous unlock operations on the same object.
Does that mean that the initialization of the chunk data is synchronized when ModifyMutex is locked on the modifying thread because it occured before ModifyMutex was unlocked?
Cheers,
Magogan