Archived

This topic is now archived and is closed to further replies.

Nash

Strange ON_Exit

Recommended Posts

I''m having a strange problem. I have some code to detect when a user hits ctrl-C (ON_SIG). I have a thread running. When the app exits, it kills the thread. However, the thread takes a long time to die. I don''t understand why. I went to the trouble of removing all non-essential code. My thread is just sleeping in loop. There''s no reason for it to take so long. Could it be the way I catch the crtl-C key board param? Thanks. bool stop; int my_thread(); int my_exit(); main() { ..... SIG_SET(); on_exit(my_exit); createthread(...my_thread); while(.... } int my_exit() { stop = true; exit_code = STILL_RUNNING; while(exit_code == STILL_RUNNING) GetExitCode(&exit_code..); } int my_thread() { while(stop != true) { Sleep(1); } exitthread(0); }

Share this post


Link to post
Share on other sites
Put also a sleep inside the wait-for-thread-to-stop-loop. Otherwise your app waits as fast as possible for the thread which almost gets no time to run.

while ( exit_code == STILL_RUNNING )
{
Sleep( 20 );
GetExitCode(&exit_code..);
}

Share this post


Link to post
Share on other sites