Changes between Version 52 and Version 53 of processus_thread


Ignore:
Timestamp:
Dec 7, 2017, 8:50:16 PM (4 years ago)
Author:
alain
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • processus_thread

    v52 v53  
    124124== __5) Thread destruction__ ==
    125125
    126 The destruction of a thread T running in cluster K can be caused by the thread itself, executing the thread_exit() function. It can also be caused by another thread, executing the thread_kill() function requesting the target thread to stop execution. In both case, the host kernel K is in charge of the destruction. The scenario is more complex if the finishing thread T is running in DETACHED mode, because the parent thread TP must be informed of the completion of thread T, in case of pthread_join() executed by TP.
     126The destruction of a thread T running in cluster K can be caused by the thread itself, executing the thread_exit() function to suicide. It can also be caused by another thread, executing  the thread_kill() function requesting the target thread to stop execution.
    127127
    128 === 5.1) thread_exit ===
     128=== 5.1) thread_kill() ===
    129129
    130  * If it is running in DETACHED mode, the calling thread T sets the FLAG_SUICIDE bit in the "flags" bit_vector, registers the BLOCKED_GLOBAL bit in the "blocked" bit_vector, and de-schedule. The scheduler, detecting the FLAG_SUICIDE bit, remove the thread from the scheduler list, remove the thread from its process, and destroys the thread descriptor.
    131  * If it is running in ATTACHED mode, the calling thread T sets the BLOCKED_EXIT bit in the "blocked" bit vector and de-schedule.  The FLAG_KILL bit in the "flags" bit-vector,  and the BLOCKED_EXIT bit are set by the parent thread TP (using remote  accesses) when it executes the pthread_join(), and detects the BLOCKED_EXIT bit in thread T. The scenario is then the kill scenario described below.
     130The thread_kill() function must be executed by a thread running in kernel mode in the same cluster as the target thread. It is called by the pthread_cancel() system call, to destroy one single thread, or by the kill() system call, to destroy all thread of a given process. The killer thread requires the target thread scheduler to do the job by writing in the target thread descriptor, and the target scheduler signals completion to the killer by writing in the killer thread descriptor.
    132131
    133 === 5.2) thread_kill ===
     132 * To request the kill, the killer thread  sets the BLOCKED_GLOBAL bit in the target thread "blocked" field, sets the SIG_KILL bit in the target thread "signals" field, and register in the target thread "kill_rsp" field the address of a response counter allocated in the killer thread stack.
     133 * 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.
     134 * 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, release the memory allocated to the target thread descriptor, and atomically decrement the response counter in the killer thread to signal completion.
    134135
    135 The killer thread uses a remote access to set the BLOCKED_GLOBAL bit in the target thread "blocked" bit_vector, set the FLAG_KILL bit in the target thread "signals" bit_vector, and send an IPI to the target thread core to force scheduling.
    136 The target thread scheduler, detecting the FLAG_KILL bit set, removes the thread from the scheduler list, removes the thread from the local process descriptor, and finally destroys the thread descriptor.
     136=== 5.2) thread_exit() when DETACHED ===
     137
     138The thread_exit() is called by an user thread T executing the pthread_exit system call to suicide. The scenario is rather simple when the thread T is not running in ATTACHED mode.
     139
     140 * The thread_exit() function  sets the SIG_SUICIDE bit in the thread "signals" bit_vector, sets the BLOCKED_GLOBAL bit in the thread "blocked" bit_vector, and de-schedule.
     141 * The scheduler, detecting the SIG_SUICIDE bit, detach the thread from the scheduler, detach the thread from the local process descriptor, and releases the memory allocated to the thread descriptor.
     142
     143== 5.3) thread_exit when ATTACHED ===
     144
     145The thread_exit() scenario is more complex if the finishing thread T is running in ATTACHED mode, because another thread PT executing the pthread_join() system call must be informed of the exit of thread T. As the pthread_exit() can happen before of after the pthread_join(), this requires a synchronisation. This synchronisation uses three fields in thread descriptor:
     146
     147 remote_spin_lock implemented in the T thread descriptor,
     148
     149 * The thread T try to take the locksets the BLOCKED_EXIT bit in the "blocked" bit vector and de-schedule.  The FLAG_KILL bit in the "flags" bit-vector,  and the BLOCKED_EXIT bit are set by the parent thread TP (using remote  accesses) when it executes the pthread_join(), and detects the BLOCKED_EXIT bit in thread T. The scenario is then the kill scenario described below.
     150 * The thread PT try to take the lock
    137151
    138152== __6) Process destruction__ ==