Well, I've been looking into multithreading to do a single (but tedious) task. I am creating a space sim that allows the player to travel between stars. During the travel time, I will be generating the "new" star system. This task creates all the planets ,the terrain texture, and the atmosphere textures. Needless to say, this is a HUGE drain on the program; so I broke it up into passes. This works ok, but I still run into systems with a lot of planets, so this takes several thousand passes to get everything generated. This means that some times I reach the system before everything is generated and I had to make a "while" statement to finish the generation.....
I have never done multithreading before and I don't know how to make it work. The examples seem to want me to create the thread and have it exit when finished.
DWORD WINAPI MyThreadFunction( bool Exit ){
tp3++;
return 0;
}
(Ignore the "bool Exit" parameter).... This will only increment tp3 once, and that makes sense but when I do something like:
DWORD WINAPI MyThreadFunction( bool Exit ){
while (true) tp3++;
return 0;
}
It does nothing at all......
tp3 is a global variable I use in the program. Here is the creation:
HANDLE th=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)&MyThreadFunction,NULL,0,NULL);
I was thinking, perhaps, I should do the thread creation whenever I need to generate and just leave it at that.... Would that work? I don't want to create memory leaks or something like that.....