Changes between Version 64 and Version 65 of processus_thread


Ignore:
Timestamp:
Dec 9, 2017, 9:34:12 PM (4 years ago)
Author:
alain
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • processus_thread

    v64 v65  
    115115The 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.
    116116
    117 === 5.1) thread_kill() ===
     117=== 5.1) thread kill ===
    118118
    119 The 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 threads 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.
     119The '''thread_kill()''' kernel function can be executed by a thread running in any cluster. It is called by the ''pthread_cancel'' system call, to destroy one single thread, or by the ''kill'' system call, to destroy all threads 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.
    120120
    121121 * 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.
     
    123123 * 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.
    124124
    125 === 5.2) thread_exit() when DETACHED ===
     125=== 5.2) thread exit when DETACHED ===
    126126
    127 The 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.
     127The '''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.
    128128
    129  * 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.
     129 * 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.
    130130 * 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.
    131131
    132 === 5.3) thread_exit() when ATTACHED ===
     132=== 5.3) thread exit when ATTACHED ===
    133133
    134 The thread_exit() scenario 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 ''pthread_exit'' and the ''pthread_join'' can happen 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 "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:
     134The '''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:
    135135
    136  * Both the T thread (executing the thread_exit() function), and the PT thread (executing the 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).
    137  * After taking the "join_lock", the T thread registers its exit value in the T thread "join_value" field, and test the JOIN_DONE flag in the T thread "flags" field:
     136 * 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).
     137 * The T thread registers its exit value in the T thread "join_value" field, and test the JOIN_DONE flag in the T thread "flags" field:
    138138   * If the JOIN_DONE flag is set, the PT thread arrived first and is blocked: the T thread reset the  BLOCKED_EXIT bit in the PT thread (using the extended pointer stored in the "join_xp" field), reset the JOIN_DONE flag, releases the "join_lock" in T thread, and exit as described in the DETACHED case.
    139139   * If the JOIN_DONE flag is not set, the T thread T arrived first: the T thread set the BLOCKED_JOIN bit in the T thread "blocked" field, releases the "join"lock", and deschedules.
    140  * After taking the "join_lock", the PT thread test the BLOCKED_JOIN bit in T thread.
     140 * The PT thread test the BLOCKED_JOIN bit in T thread:
    141141   * If the BLOCKED_JOIN bit is set, the T thread arrived first and is blocked: the PT thread reset the BLOCKED_JOIN bit in the T thread, get the exit value from the T thread i "join_value" field, releases the "join_lock" in T thread, and continue.
    142142   * If the BLOCKED_JOIN bit is not set, the PT thread arrived first: the PT thread register its extended pointer in the T thread "join_xp" field, set the JOIN_DONE flag in the T thread, sets the BLOCKED_EXIT bit in the PT thread "blocked" field, releases the "join_lock" in the T thread, and deschedules.