Changes between Version 82 and Version 83 of processus_thread


Ignore:
Timestamp:
Mar 1, 2018, 11:19:25 AM (4 years ago)
Author:
alain
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • processus_thread

    v82 v83  
    122122The destruction of an user thread T can be caused by another thread C, executing  the ''pthread_cancel()'' sys call requesting the target thread to stop execution. It can also be caused by the thread T itself, executing the ''pthread_exit()'' sys call to suicide. Finally, it can also be caused by the ''exit()'' or ''kill()'' syscalsl requesting the destruction of all threads of a given process.   
    123123
    124 === 5.1) thread kill ===
     124TODO : handle the special case of the main thread...
    125125
    126 The '''thread_kill()''' kernel function is executed by a killer thread that must be different from the target thread, and must be running in the same cluster as the target thread. The killer thread requires the target thread scheduler to do the work at the next scheduling point, by writing in the target thread descriptor, and the target scheduler signals completion to the killer by writing an acknowledge in a specified location in the killer stack.
     126=== 5.1) thread running in DETACHED mode ===
    127127
    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.
     128The scenario is rather simple when the target thread is not running in ATTACHED mode.
     129The '''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.
     134At the next scheduling point,
     135
     136
     137
     138
     139and registers in the target thread ''ack_rsp_count'' field a pointer on the location where the acknowledge must be written.
    129140 * 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.
    130141 * 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.
    131142
    132 === 5.2) thread exit when DETACHED ===
     143=== 5.2) thread running in ATTACHED mode ===
    133144
    134 The '''sys_thread_exit()''' kernel function 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.
    135145
    136146 * The sys_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.
    137  * 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.
    138147
    139 === 5.3) thread exit when ATTACHED ===
    140148
    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
     151The 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:
    142152
    143153 * Both the T thread (executing the sys_thread_exit() function), and the PT thread (executing the sys_thread_join() function) try to take the "join_lock" implemented in the T thread descriptor (the "join_lock" in the PT thread is not used).