Does End Stop all threads?

Just starting out? Need help? Post your questions and find answers here.
funnyguy
User
User
Posts: 69
Joined: Mon Jun 23, 2008 10:57 pm

Does End Stop all threads?

Post by funnyguy »

I've been having some issues with my program... Some threads don't end when End is called... the program just hangs without closing. Is this normal? if not is there a obvious reason?
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

If the program uses End, all threads will be terminated too.
If your threads don't want to go to bed, then they are either heavily busy (e. g. using very much CPU) or you may have a mutex-problem. Your main-program cannot continue, because it waits for a mutex that one of your threads has locked.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

Considering you have no idea which threads are terminating in what order it's good practice to signal all threads to exit and wait until they've done so (with a timeout, of course) before terminating the program.

If a timeout has occurred then the thread is probably stuck in an infinite loop somewhere and, unless it's known to be busy for extended periods of time, this most likely signifies a bug or improper handling of your end-case.

If a thread can't be signaled early enough then you can opt for terminating it altogether. Only do this if you know that it won't lock or break any other threads. Also consider that you may need to handle some additional cleanup if the thread has any outstanding API handles that need to be closed.

If you plan on terminating a thread then be sure to handle any case where the result may be unexpected (thread does not exists or is an orphaned handle, if you're using API, or WaitThread when no thread exists).

Sounds pretty simple, right? Happy threading!
Post Reply