Changes between Version 90 and Version 91 of processus_thread
- Timestamp:
- Mar 2, 2018, 10:06:37 AM (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
processus_thread
v90 v91 120 120 == __5) Thread destruction__ == 121 121 122 The destruction of a n userthread 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.122 The destruction of a target 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 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 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).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 by another 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()'' syscall (see section [6] below). 127 If the target thread is running in attached mode, the '''thread_kill()''' function synchronize with the joining thread, waiting the actual execution of the pthread_join() syscall before marking the target thread for delete. 128 129 If the target thread is main thread (i.e. the thread 0 in the process owner cluster) the '''thread_kill()''' does not mark the target thread for delete, because this must be done by the parent process main thread executing the ''sys_wait()'' syscall (see section [6] below). 128 130 129 131 === 5.1) thread running in DETACHED mode === … … 150 152 * If the FLAG_KILL_DONE is set, the K thread arrived first and is blocked on the BLOCKED_JOIN condition: the J thread unblocks the killer thread, reset the FLAF_KILL_DONE in the T thread, releases the "join_lock" in T thread, and returns. 151 153 * If the FLAG_KILL_DONE is not set, the J thread arrived first: the J thread register its extended pointer in the T thread "join_xp" field, set the FLAG_JOIN_DONE in the T thread, sets the BLOCKED_EXIT bit in the J thread, releases the "join_lock" in the T thread, and deschedules. It simply returns when it is unblocked by the K thread. 154 155 === 5.3) main thread destruction === 152 156 153 157 == __6) Process destruction__ ==