Ok to use 'END' in a thread?
Ok to use 'END' in a thread?
I have a program that runs a thread and I just tried to use 'end' in the thread rather than the main program and it ended the program no probs (Win10+FB1.01) so just wondering if this is ok to do (seems to be) as it suits my program better :)
-
- Posts: 556
- Joined: Mar 10, 2007 15:44
- Location: Ohio, USA
- Contact:
Re: Ok to use 'END' in a thread?
I am not an expert but I would say no.
ThreadWait waits for a thread created by ThreadCreate or Threadcall to finish execution, and then releases the resources associated with the thread handle.
Re: Ok to use 'END' in a thread?
Even used in the main code, 'End' is not a good way to exit the program.
As highlights the documentation:
As highlights the documentation:
Usage of this statement does not cleanly close scope. Local variables will not have their destructors called automatically, because FreeBASIC does not do stack unwinding. Only the destructors of global variables will be called in this case.
For this reason, it is discouraged to use End simply to mark the end of a program; the program will come to an end automatically, and in a cleaner fashion, when the last line of module-level code has executed.
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: Ok to use 'END' in a thread?
You might view https://stackoverflow.com/a/36094799/446106 as a recommendation to use the C Runtime's _exit() to end a program from within a thread:
But like FB's End(), it won't cleanly exit scopes or clean up variables. Allocated memory should be cleaned up though.
Code: Select all
#include "crt/stdlib.bi"
...
_exit(1)
Re: Ok to use 'END' in a thread?
thaks guys and yeh counting_pine might try that _exit(1) although my program does only have 1 non global variable.