Changes between Version 121 and Version 122 of processus_thread


Ignore:
Timestamp:
Nov 6, 2019, 12:42:10 AM (4 years ago)
Author:
alain
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • processus_thread

    v121 v122  
    146146The thread destruction is more complex if the target thread T is running in ATTACHED mode, because another joining thread J must be informed of the termination of thread T. As the '''thread_delete()''' function (executed by the killer thread K) and the '''sys_thread_join()''' function (executed by the joining thread J) can be executed in any order, this requires a "rendez-vous": The first arrived thread blocks and deschedules. It will be unblocked by the other thread.
    147147
    148 The destruction mechanism can therefore involve three threads: the target thread T, the killer thread K, and the joining thread J. It
     148The destruction mechanism can therefore involve three threads: the target thread T, the killer thread K, and the joining thread J.
    149149
    150150It uses three specific fields in the thread descriptor:
     
    156156 * Both the killer thread K, (executing the thread_kill() or the thread_exit() function), and the joining thread J (executing the sys_thread_join() function), try to take the ''join_lock'' implemented in the T thread descriptor (the ''join_lock'' in the J thread is not used).
    157157 * After taking the lock, the K thread test the FLAG_JOIN_DONE in the T thread descriptor:
    158    * If the FLAG_JOIN_DONE is set, the J thread arrived first and is blocked on the BLOCKED_JOIN condition: the K thread registers the exit status in the J thread ''exit_status'' field (only when the K thread is the T pthread itself executing the pthread_exit() function), unblocks the J thread from the BLOCKED_JOIN condition (using the ''join_xp'' field in the T thread), reset the JOIN_DONE flag in T thread,   releases the ''join_lock'' in T thread, and finally completes the T thread destruction as described in the detached case.
    159    * If the FLAG_JOIN_DONE is not set, the K thread arrived first: the K thread blocks the K thread on the BLOCKED_JOIN condition, sets the FLAG_KILL_DONE in the T thread, registers the exit status in the T thread ''exit_status'' field (only when the K thread is the T pthread itself executing the pthread_exit() function), registers the killer thread extended pointer in the T thread ''join_xp'' field, releases the ''join_lock'' in the T thread, and deschedules. It completes the T thread destruction as described in the detached case when it is unblocked by the J thread.
     158   * If the FLAG_JOIN_DONE is set, the J thread arrived first and is blocked on the BLOCKED_JOIN condition: the K thread copies the exit_status from the the T thread to the J thread ''exit_status'' field (because the T thread can be deleted before the J thread resumes), unblocks the J thread from the BLOCKED_JOIN condition (using the ''join_xp'' field in the T thread), reset the JOIN_DONE flag in T thread,   releases the ''join_lock'' in T thread, and finally completes the T thread destruction as described in the detached case.
     159   * If the FLAG_JOIN_DONE is not set, the K thread arrived first: the K thread blocks the K thread on the BLOCKED_JOIN condition, sets the FLAG_KILL_DONE in the T thread, registers the killer thread extended pointer in the T thread ''join_xp'' field, releases the ''join_lock'' in the T thread, and deschedules. It completes the T thread destruction as described in the detached case when it is unblocked by the J thread.
    160160 * After taking the lock, the J thread tests the FLAG_KILL_DONE in the T thread descriptor:
    161    * If the FLAG_KILL_DONE is set, the K thread arrived first and is blocked on the BLOCKED_JOIN condition: the J thread get the ''exit_status'' from the T thread to the J thread descriptor, unblocks the K thread, resets the FLAG_KILL_DONE in the T thread, releases the "join_lock" in T thread, and returns.
    162    * If the FLAG_KILL_DONE is not set, the J thread arrived first: the J thread registers its extended pointer in the T thread "join_xp" field, set the FLAG_JOIN_DONE in the T thread, sets the BLOCKED_EXIT bit in the J thread, releases the "join_lock" in the T thread, and deschedules. It get the ''exit_status'' from its own T thread and  returns when it is unblocked by the K thread.
     161   * If the FLAG_KILL_DONE is set, the K thread arrived first and is blocked on the BLOCKED_JOIN condition: the J thread get the ''exit_status'' from the T thread to the J thread descriptor, unblocks the K thread, resets the FLAG_KILL_DONE in the T thread, releases the "join_lock" in T thread, and returns the exit_value from the T thread descriptor.
     162   * If the FLAG_KILL_DONE is not set, the J thread arrived first: the J thread registers its extended pointer in the T thread "join_xp" field, set the FLAG_JOIN_DONE in the T thread, sets the BLOCKED_EXIT bit in the J thread, releases the "join_lock" in the T thread, and deschedules. It returns the ''exit_status'' from its own J thread descriptor when it is unblocked by the K thread.
    163163
    164164== __6) Process destruction__ ==