Changes between Version 61 and Version 62 of processus_thread


Ignore:
Timestamp:
Dec 8, 2017, 1:56:14 PM (6 years ago)
Author:
alain
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • processus_thread

    v61 v62  
    133133=== 5.3) thread_exit() when ATTACHED ===
    134134
    135 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'' can happen before of after the ''pthread_join'', this requires a synchronisation: 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. The scenario is not symmetrical, because the PT thread can access the T thread descriptor, but the T thread cannot access the PT thread descriptor before the pthread_join execution:
     135The 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:
    136136
    137137 * 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).
    138138 * After taking the "join_lock", the T thread register its exit value in the T thread "join_value" field, and test the JOIN_DONE flag in the T thread "flags" field:
    139    * 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), releases the "join_lock" in T thread, and exit as described for the DETACHED case.
    140    * If the JOIN_DONE flag is not set, the T thread T arrived first: The T thread set the EXIT_DONE flag in the T thread "flags"field, release the "join"lock", set the BLOCKED_JOIN bit in the T thread "blocked" field, and deschedules.
    141  * After taking the "join_lock", the PT thread test the EXIT_DONE flag in T thread.
    142    * If the EXIT_DONE flag 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 the "join_value" field, releases the "join_lock" in T thread, and continue.
    143    * If the EXIT_DONE flag 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, releases the "join_lock" in the T thread, sets the BLOCKED_EXIT bit in the PT thread "blocked" field, and deschedules.
     139   * 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.
     140   * 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.
     141 * After taking the "join_lock", the PT thread test the BLOCKED_JOIN bit in T thread.
     142   * 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 the "join_value" field, releases the "join_lock" in T thread, and continue.
     143   * 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.
    144144
    145145== __6) Process destruction__ ==