I’m creating a networked 4-player puzzle game, and I’m doing my simulation
of each of the four playing fields in different threads. The simulation
itself runs fine on all the threads, but when the threads return,
sometimes “Dr Watson,” which I’m guessing to be the Win32 thread manager
of some kind, errors and complains that it could not attach to a thread,
with a message saying “Windows 2000 error code = 87 / The parameter is
incorrect.” Then the program itself crashes with error message " has generated errors and will be closed by windows." It’s
not consistent, and does not occur at all when I only run the Renderer and
one player simulation. It occurs with greater frequency the more
simulation threads I have. I’m really not sure what’s going on, I’m kind
of new to this. Here’s my code calling the threads, and my event poller
(quit is a global bool, and is the test condition for the while loop that
keeps the threads from returning). Thanks for any help.
~Greg Peele
printf("Starting rendering\n");
Renderer = SDL_CreateThread(RenderScreen, NULL);
player.simThread = SDL_CreateThread(Testing_Pattern, &player);
printf("Player simulation thread started\n");
opponent1.simThread = SDL_CreateThread(Testing_Pattern, &opponent1);
printf("Opponent 1 simulation thread started\n");
opponent2.simThread = SDL_CreateThread(Testing_Pattern, &opponent2);
printf("Opponent 2 simulation thread started\n");
opponent3.simThread = SDL_CreateThread(Testing_Pattern, &opponent3);
printf("Opponent 1 simulation thread started\n");
while(!quit)
{
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT || (event.type == SDL_KEYDOWN &&
event.key.keysym.sym == SDLK_ESCAPE))
{
quit = true;
SDL_WaitThread(player.simThread, NULL);
SDL_WaitThread(opponent1.simThread, NULL);
SDL_WaitThread(opponent2.simThread, NULL);
SDL_WaitThread(opponent3.simThread, NULL);
SDL_WaitThread(Renderer, NULL);
}
}
}
return 0;