128 | | * 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 registers in the target thread ''ack_rsp_count'' field a pointer on the location where the acknowledge must be written. |
| 128 | The scenario is rather simple when the target thread is not running in ATTACHED mode. |
| 129 | The '''thread_kill()''' kernel function is executed by a killer thread. This killer thread can the target thread itself (for a pthread_exit() sys call), or can be another thread running in any cluster. The killer thread requires the target thread scheduler to do the work at the next scheduling point, by writing in the target thread descriptor : |
| 130 | * the killer thread sets the BLOCKED_GLOBAL bit in the target thread ''blocked'' field, |
| 131 | * for an exit, the calling thread sets the THREAD_FLAG_REQ_EXIT bit in the target thread ''flags'' field, |
| 132 | * for a cancel, the calling thread sets the THREAD_FLAG_REQ_KILL bit in the target thread ''flags'' field, |
| 133 | * at the next scheduling point, the target 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. |
| 134 | At the next scheduling point, |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | and registers in the target thread ''ack_rsp_count'' field a pointer on the location where the acknowledge must be written. |
141 | | The '''sys_thread_exit()''' function is more complex if the finishing thread T is running in ATTACHED mode, because another - possibly remote - PT thread, executing the ''pthread_join'' system call, must be informed of the exit of thread T. As the '''sys_thread_exit()''' and the '''sys_thread_join''' function can be executed in any order, this requires a "rendez-vous": The first arrived thread block and deschedule, and must be reactivated by the other thread. This synchronisation uses three specific fields in the thread descriptor: the "join_lock" field is a remote_spin_lock; the "join_value" field contains the exit value returned by the finishing thread T; the "join_xp"field contains an extended pointer on the PT thread that wants to join. It uses one specific JOIN_DONE flag in the thread descriptor "flags" field. The scenario is not symmetrical, because the PT thread can access the T thread descriptor at any time, but the T thread cannot access the PT thread descriptor before the pthread_join execution: |
| 149 | === 5.3) thread running in ATTACHED mode === |
| 150 | |
| 151 | The thread termination is more complex if the thread T is running in ATTACHED mode, because another - possibly remote - PT thread, executing the ''pthread_join'' system call, must be informed of the termination of thread T. As the '''sys_thread_exit()''' (or ''sys_thread_cancel()'') function on one hand, and the '''sys_thread_join()''' on the other hand, can be executed in any order, this requires a "rendez-vous": The first arrived thread block and deschedule, and must be reactivated by the other thread. This synchronisation uses three specific fields in the thread descriptor: the "join_lock" field is a remote_spin_lock; the "join_value" field contains the exit value returned by the finishing thread T; the "join_xp"field contains an extended pointer on the PT thread that wants to join. It uses one specific JOIN_DONE flag in the thread descriptor "flags" field. The scenario is not symmetrical, because the PT thread can access the T thread descriptor at any time, but the T thread cannot access the PT thread descriptor before the pthread_join execution: |