Changes between Version 86 and Version 87 of processus_thread
- Timestamp:
- Mar 1, 2018, 1:24:45 PM (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
processus_thread
v86 v87 120 120 == __5) Thread destruction__ == 121 121 122 The destruction of an user thread T can be caused by another thread K, executing the ''pthread_cancel()'' sys call requesting the target thread T to stop execution. It can be caused by the thread T itself, executing the ''pthread_exit()'' sys call to suicide. Finally, it can be caused by the ''exit()'' or ''kill()'' syscal slrequesting the destruction of all threads of a given process.122 The destruction of an user thread T can be caused by another thread K, executing the ''pthread_cancel()'' sys call requesting the target thread T to stop execution. It can be caused by the thread T itself, executing the ''pthread_exit()'' sys call to suicide. Finally, it can be caused by the ''exit()'' or ''kill()'' syscalls requesting the destruction of all threads of a given process. 123 123 124 The unique method to destroy a thread is to call the '''thread_kill()''' function, that set the THREAD_FLAG_REQ_DELETE in the ''flags'' field of the target thread descriptor. The thread will be asynchronously deleted by the scheduler at the next scheduling point,124 The unique method to destroy a thread is to call the '''thread_kill()''' function, that set the THREAD_FLAG_REQ_DELETE bit in the ''flags'' field of the target thread descriptor. The thread will be asynchronously deleted by the scheduler at the next scheduling point, 125 125 that calls the ''thread_destroy()'' function. This function detach the thread from the scheduler, detach the thread from the local process descriptor, and releases the memory allocated to the thread descriptor. The '''thread_kill(''') function can be called by the ''target'' thread itself (for an exit), or it can be done by another ''killer'' thread (for a kill). 126 126 127 The main thread (i.e. the thread 0 in the process owner cluster) is a special case, because the main thread of a given process can only be deleted (i.e. marked for delete) by the parent process main thread executing the sys_wait() scale(see section [6] below).127 The main thread (i.e. the thread 0 in the process owner cluster) is a special case, because the main thread of a given process can only be deleted (i.e. marked for delete) by the parent process main thread executing the ''sys_wait()'' syscall (see section [6] below). 128 128 129 129 === 5.1) thread running in DETACHED mode === 130 130 131 The scenario is rather simple when the target thread is not running in ATTACHED mode.131 The scenario is rather simple when the target thread T is not running in ATTACHED mode. 132 132 The killer thread (that can be the target thread itself for an exit) call the thread_kill() function that does the following actions: 133 133 * the killer thread sets the THREAD_BLOCKED_GLOBAL bit in the target thread ''blocked'' field, 134 134 * the killer thread sets the THREAD_FLAG_REQ_DELETE bit in the target thread ''flags'' field, 135 135 * the killer thread returns without waiting the actual deletion. 136 137 138 139 #######140 and registers in the target thread ''ack_rsp_count'' field a pointer on the location where the acknowledge must be written.141 * If the target thread is running on another core than the killer thread, the killer thread send an IPI to the core running the target thread, to ask the target scheduler to handle the request. If the target is running on the same thread as the killer, the killer thread calls directly the sched_handle_signal() function.142 * In both cases, the sched_handle_signals() function - detecting the SIG_KILL signal - detach the target thread from the scheduler, detach the target thread from the local process descriptor, detach the target thread from the parent thread if it is attached, release the memory allocated to the target thread descriptor, and atomically decrement the response counter in the killer thread to signal completion.143 #######144 136 145 137 === 5.2) thread running in ATTACHED mode ===