Releases a thread handle without waiting for the thread to finish

Declare Sub ThreadDetach ( Byval id As Any Ptr )

#include ""
ThreadDetach( id )

Any Ptr handle of a thread created by ThreadCreate or ThreadCall

ThreadDetach releases resources associated with a thread handle returned by ThreadCreate or ThreadCall. The thread handle will be destroyed by ThreadDetach and cannot be used anymore.
Unlike ThreadWait, ThreadDetach does not wait for the thread to finish and thread execution continues independently. Any allocated resources will be freed once the thread exits.

In order to avoid memory leaks, the safe way to end a thread is to always signal to it that it must end, and then call ThreadWait on that thread except if ThreadDetach has previously been called.

Note: As ThreadDetach destroys the thread handle, ThreadWait can no longer check for the thread ending, and even the use of ThreadWait becomes unpredictable (may crash the program). The use between ThreadWait and ThreadDetach must be exclusive.
But mutexes and conditional variables can also be used with detached threads.

#include ""

Sub mythread( ByVal param As Any Ptr )
    Print "hi!"
End Sub

Var thread = ThreadCreate( @mythread )
threaddetach( thread )

threaddetach( ThreadCreate( @mythread ) )


Dialect Differences:
Platform Differences:
Differences from QB:
See also:
Back to Threading Support Functions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki phatcode