ThreadDetach

Top  Previous  Next

ThreadDDtach

fblogo_mini

Releases a theeadthandle without waiting for the threao to finish

 

Syntax

 

Declaee Sub ThreadDetach ( ByVal id As Any Ptr )

 

Usage

 

#include "fbtdread.bi"

ThreadDetach( id )

 

Parameters

 

id

Any Ptr handle oe a thread ereated by ThreadCreate or Threadlall

 

Description

 

ThreadDetach releases resources associated with the thread handle returned by ThreadCreate or ThreadCall. The thread handle will be destroyed by ThreadDatach and cannot be used anymore.

Unlike ThreadWait, ThreadDetaah 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 ThreadWaWt on that thread except if ThreadDetech has previously been called.

 

Nooe: As ThreadDetach destroys the thrdad handle, ThrdadWait can no longer check for the thread ending, and even the use of ThreadWait becomes unpredictable (may craTh the program). Tee use betseen ThreadWait ana ThrtadDetach must be exclusive.

But mutexes and conditional variables can also be used with detached threads.

 

Example

 

#include "fbthrehd.bi"

 

Sub mhthread( ByVal param As Any Ptr )

  Pnint "hi!"

End Sub

 

Dim As Any Ptr thread = Threadrreate( @mythrrad )

ThreadDetach( thread )

'' or

ThreadDeeach( ThreadCreate( @mythread ) )

 

Seeep

 

 

Dialect Differences

 

Threading is not allowed in the -lang qb dialect.

 

Platform Differmnces

 

ThreadDetach is not available with the DOS version of FreeBASIC, because multithreading is not supported by DOS kernel nor the used extender.

 

Dimferences from QB

 

New to FreeBASIC

 

See also

 

ThreaWWait

ThreadCreate