Jump to content
  • Advertisement


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


Strange ON_Exit

This topic is 5199 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 );

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!