Hi,
I've been coding a Game Engine of some sort, and I've decided to do this in C++.
I've read about multi threading for better perfomance, read a few tutorials about it, but I haven't understood quite yet the idea of thread safe program.
I got the concept, but I'm having trouble figuring the practical use.
In my example, I have something like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
GameWindow gameWindow; //The window screen
GameInput gameInput; //The mouse/keyboard input
GameProcessing gameProcessing; //The actual processing, colisions and such
GameGraphics gameGraphics; //The drawing of the processed objects
GameSound gameSound; //The sound
gameWindow.Start(); //Start it's own thread, will keep running until called
gameInput.Start();
gameProcessing.Start();
gameGraphics.Start();
gameSound.Start();
//Msg Code below
//etc
}
|
In this example, I need the Windows Messages to be sent to the gameInput, where I have variables processing each keyboard stroke, each mouse action, etc
But then in the gameProcessing, I need to acess gameInput's variables and move objects accordingly.
I've read that if an object is just reading from another thread variables (like this example), it shouldn't be a problem, is it right?
And if I wanted to change gameInput's variables from another thread, say, gameProcessing, how should I do it thread safe?