TutThreadDetach allow a thread to run to completion without requiring the operating system to remember its exit code
thread
the thread to detach
TRUE
if successful, FALSE
otherwise.
If TutThreadDetach fails, it returns FALSE
and sets the global SmartSockets error number to one of:
Normally, when a thread exits, the operating system must remember the thread's exit code, which can be retrieved with TutThreadWait. This requires that every thread created with TutThreadCreate be subsequently joined with TutThreadWait. If it is not, it leaks a small amount of system resources. TutThreadDetach instructs the operating system not to remember the thread's exit code. This means that if someone calls TutThreadDetach, there is no need to call TutThreadWait. When the detached thread exits, all system resources for that thread are cleaned up.
Do not call TutThreadWait on a thread that has been detached using TutThreadDetach.
TutThreadCreate, TutThreadWait, TutThreadDetach, TutThreadExit
This example creates three threads and detaches them. Each thread executes a function that prints a simple message identifying the thread, then exits.
T_PTR T_ENTRY my_thread_func(T_PTR arg) { TutOut("This output comes from thread %d\n", *((T_INT4 *)arg); return NULL; } int func() { T_THREAD threads[3]; T_INT4 args[3]; T_INT4 i; if (!TipcInitThreads()) exit (T_EXIT_FAILURE); for (i = 0; i < 3; i++) { args[i] = i + 1; threads[i] = TutThreadCreate(my_thread_func, &args[i], NULL); if (TutThreadEqual(T_INVALID_THREAD, threads[i])) { /* error */ } if (!TutThreadDetach(threads[i])) { /* error */ } } }
TIBCO SmartSockets™ Utilities Software Release 6.8, July 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |