Revision history for KeyPgThreadDetach


Revision [22065]

Last edited on 2017-12-29 04:38:06 by fxm [Added advice to avoid the memory leaks]
Additions:
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 ##[[KeyPgThreadWait|ThreadWait]]## on that thread except if **""ThreadDetach""** has previously been called.


Revision [22061]

Edited on 2017-12-28 04:56:05 by fxm [Mutexes and conditional variables can also be used with detached threads]
Additions:
**Note:** As **""ThreadDetach""** destroys the thread handle, ##[[KeyPgThreadWait|ThreadWait]]## can no longer check for the thread ending, and even the use of ##[[KeyPgThreadWait|ThreadWait]]## becomes unpredictable (may crash the program). The use between ##[[KeyPgThreadWait|ThreadWait]]## and **""ThreadDetach""** must be exclusive.
But mutexes and conditional variables can also be used with detached threads.
Deletions:
**Note:** As **""ThreadDetach""** destroys the thread handle, ##[[KeyPgThreadWait|ThreadWait]]## can no longer check for the thread ending, and even the use of ##[[KeyPgThreadWait|ThreadWait]]## becomes unpredictable (may crash the program).
The use between ##[[KeyPgThreadWait|ThreadWait]]## and **""ThreadDetach""** must be exclusive.


Revision [21464]

Edited on 2016-05-13 12:59:51 by fxm [Added note]
Additions:

**Note:** As **""ThreadDetach""** destroys the thread handle, ##[[KeyPgThreadWait|ThreadWait]]## can no longer check for the thread ending, and even the use of ##[[KeyPgThreadWait|ThreadWait]]## becomes unpredictable (may crash the program).
The use between ##[[KeyPgThreadWait|ThreadWait]]## and **""ThreadDetach""** must be exclusive.


Revision [20551]

Edited on 2016-02-10 16:09:30 by DkLwikki [Update link format]
Additions:
[[KeyPgDeclare|Declare]] [[KeyPgSub|Sub]] **""ThreadDetach""** ( [[KeyPgByval|Byval]] //id// [[KeyPgAs|As]] [[KeyPgAny|Any]] [[KeyPgPtr|Ptr]] )
##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]## handle of a thread created by ##[[KeyPgThreadCreate|ThreadCreate]]## or ##[[KeyPgThreadCall|ThreadCall]]##
**""ThreadDetach""** releases resources associated with a thread handle returned by ##[[KeyPgThreadCreate|ThreadCreate]]## or ##[[KeyPgThreadCall|ThreadCall]]##. The thread handle will be destroyed by **""ThreadDetach""** and cannot be used anymore.
Unlike ##[[KeyPgThreadWait|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.
- Threading is not allowed in the //[[CompilerOptlang|-lang qb]]// dialect.
- ##[[KeyPgThreadWait|ThreadWait]]##
- ##[[KeyPgThreadCreate|ThreadCreate]]##
Deletions:
[[KeyPgDeclare Declare]] [[KeyPgSub Sub]] **""ThreadDetach""** ( [[KeyPgByval Byval]] //id// [[KeyPgAs As]] [[KeyPgAny Any]] [[KeyPgPtr Ptr]] )
##[[KeyPgAny Any]] [[KeyPgPtr Ptr]]## handle of a thread created by ##[[KeyPgThreadCreate ThreadCreate]]## or ##[[KeyPgThreadCall ThreadCall]]##
**""ThreadDetach""** releases resources associated with a thread handle returned by ##[[KeyPgThreadCreate ThreadCreate]]## or ##[[KeyPgThreadCall ThreadCall]]##. The thread handle will be destroyed by **""ThreadDetach""** and cannot be used anymore.
Unlike ##[[KeyPgThreadWait 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.
- Threading is not allowed in the //[[CompilerOptlang -lang qb]]// dialect.
- ##[[KeyPgThreadWait ThreadWait]]##
- ##[[KeyPgThreadCreate ThreadCreate]]##


Revision [17069]

Edited on 2014-04-28 13:35:09 by FxMwikki [Some additions.]
Additions:
**""ThreadDetach""** releases resources associated with a thread handle returned by ##[[KeyPgThreadCreate ThreadCreate]]## or ##[[KeyPgThreadCall ThreadCall]]##. The thread handle will be destroyed by **""ThreadDetach""** and cannot be used anymore.
Unlike ##[[KeyPgThreadWait 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.
Deletions:
**""ThreadDetach""** releases resources associated with a thread handle returned by ##[[KeyPgThreadCreate ThreadCreate]]## or ##[[KeyPgThreadCall ThreadCall]]##. Unlike ##[[KeyPgThreadWait ThreadWait]]##, **""ThreadDetach""** does not wait for the thread to finish.


Revision [17064]

Edited on 2014-04-28 08:35:34 by DkLwikki [Add ThreadDetach]
Additions:
[[KeyPgDeclare Declare]] [[KeyPgSub Sub]] **""ThreadDetach""** ( [[KeyPgByval Byval]] //id// [[KeyPgAs As]] [[KeyPgAny Any]] [[KeyPgPtr Ptr]] )
**""ThreadDetach""**( //id// )
**""ThreadDetach""** releases resources associated with a thread handle returned by ##[[KeyPgThreadCreate ThreadCreate]]## or ##[[KeyPgThreadCall ThreadCall]]##. Unlike ##[[KeyPgThreadWait ThreadWait]]##, **""ThreadDetach""** does not wait for the thread to finish.
- **""ThreadDetach""** is not available with the DOS version of ""FreeBASIC"", because multithreading is not supported by DOS kernel nor the used extender.
Deletions:
[[KeyPgDeclare Declare]] [[KeyPgSub Sub]] **ThreadDetach** ( [[KeyPgByval Byval]] //id// [[KeyPgAs As]] [[KeyPgAny Any]] [[KeyPgPtr Ptr]] )
**ThreadDetach**( //id// )
**ThreadDetach** releases resources associated with a thread handle returned by ##[[KeyPgThreadCreate ThreadCreate]]## or ##[[KeyPgThreadCall ThreadCall]]##. Unlike ##[[KeyPgThreadWait ThreadWait]]##, **ThreadDetach** does not wait for the thread to finish.
- **ThreadDetach** is not available with the DOS version of ""FreeBASIC"", because multithreading is not supported by DOS kernel nor the used extender.


Revision [17063]

The oldest known version of this page was created on 2014-04-28 08:34:18 by DkLwikki [Add ThreadDetach]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode