why it's an error use a Sleep() for end a program?

why it's an error use a Sleep() for end a program?
imagine that we are using a timer:
1 - uses 'new' and creates more objects;
2 - the timer procedure continues for, on end, delete the objects.
if i end up the program. the timer destructor terminates the timer, but, maybe don't delete the objects.
so, on my opinion, is correct use the Sleep() for help the CPU win time for finish the job... right?
closed account (E0p9LyTq)
Sleep() stops the execution of the app, dead, for the specified time. Actually Sleep() only affects the thread it was called from, but with many apps that is the main thread. If there are deallocation/cleanup tasks still to be performed in the main thread they are put on hold.

Using Sleep() doesn't help at all.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms686298(v=vs.85).aspx

Last edited on
true stops the actual thread. but using timers and new threads, before end the program, helps more finish the others threads and timers. i'm saying in these situation.
closed account (E0p9LyTq)
You are suggesting swinging a 10 kilo sledge in an attempt to swat a gnat on another continent.

The compiler will/should create machine code that will obviate any need on your part to be concerned about automatic clean up of properly created objects.

You create malformed objects/object pointers using raw news and all bets still the compiler should try to manage a proper clean up.

But this is Windows we are talking about, and sometimes even well managed/created code misfires, requiring a soft, or hard, reboot.

Windows 10 appears to me to have better resource management over all the previous versions, but still I need to log out/reboot from time to time.
on new threads\timer, i don't have sure if the program finish the thread(i'm not speaking about synchronization) before ends the program. what you can tell me?
Topic archived. No new replies allowed.