Multithreading with mutexes and time constraints 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: 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 https://ift.tt/eA8V8J
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: 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
from GameDev.net http://bit.ly/2D1rboB
from GameDev.net http://bit.ly/2D1rboB
ليست هناك تعليقات