

Often, you want data specific to a particular thread. Le_thread_Join() fetches the return/exit value of the thread that it joined with. This also means that if a thread is joinable, someone must join with it, or its resources will never get cleaned up (until the process terminates). But, a joinable thread doesn't disappear until another thread "joins" with it. Normally, when a thread terminates, it disappears. le_thread_Join(T) blocks the calling thread until thread T exits.įor a thread to be joinable, it must have its "joinable" attribute set (using le_thread_SetJoinable()) prior to being started. Joining is done by a call to le_thread_Join(). Forking is done by creating and starting a thread. Sometimes, you want single execution thread split (fork) into separate threads of parallel execution and later join back together into one thread later. If a cancellation request is made (by calling le_thread_Cancel() or pthread_cancel()), it will be blocked and remain in a pending state until cancellation is unblocked (also using pthread_setcancelstate()), at which time the thread will be immediately cancelled. To prevent cancellation during a critical section (e.g., when a mutex lock is held), pthread_setcancelstate() can be called.

See 'man 7 pthreads' for more information on cancellation and cancellation points. If it is in the middle of doing something that can't be interrupted, it will not terminate until it is finished. See Joining for more information.Ĭanceling a thread may not cause the thread to terminate immediately. If a thread terminates itself, and it is "joinable", it can pass a void* value to another thread that "joins" with it. Threads can also tell other threads to terminate by "canceling" them done through a call to le_thread_Cancel(). No other thread should try to set any attributes of T2 or try to start it.

Warning It is assumed that if a thread T1 creates another thread T2 then only thread T1 will set the attributes and start thread T2. When all attributes have been set, the thread can be started by calling le_thread_Start(). All attributes have default values so it is not necessary to set any attributes (other than the name and main function address, which are passed into le_thread_Create() ). In this state, attributes like scheduling priority and stack size can use the appropriate "Set" functions. Threads are created in a suspended state.
#Join and cancel pthread c software
Sometimes, this style doesn't fit well with a problem being solved, so you're forced to implement workarounds that severely complicate the software design.
