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() 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. |
| 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. |
135 | | This is a three steps scenario: |
136 | | |
137 | | 1. 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. |
138 | | 1. The target thread scheduler, detecting the FLAG_KILL bit set, removes the thread from the scheduler list, and reset the FLAG_KILL bit to acknowledge the killer. |
139 | | 1. The killer thread poll the FLAG_KILL bit in the target thread until reset, detach the thread from its parent if the thread is attached, and destroys the target thread, using a RPC_THREAD_DESTROY if the target thread is remote. |
140 | | |
141 | | |
142 | | |
143 | | === 5.3) phase 3 === |
144 | | |
145 | | In each cluster, a dedicated kernel thread is in charge of housekeeping: This thread releases the memory allocated to all DEAD threads. |
| 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. |