Changes between Version 85 and Version 86 of processus_thread


Ignore:
Timestamp:
Mar 1, 2018, 1:20:30 PM (6 years ago)
Author:
alain
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • processus_thread

    v85 v86  
    109109== __4) Thread creation__ ==
    110110
    111 Any thread T of any process P, running in any cluster K, can create a new thread NT in any cluster M. This creation is initiated by the ''pthread_create'' system call. The target M cluster is called the host cluster.
    112  * The target cluster M can be specified by the user application, using the CXY field of the pthread_attr_t argument. If the CXY is not defined by the user, the target cluster M is selected by the kernel K, using the DQDT.
    113  * The target core in cluster M can be specified by the user application, using the CORE_LID field of the pthread_attr_t argument. If the CORE_LID is not defined by the user, the target core is selected by the target kernel M.
     111Any user thread T of any process P, running in any cluster K, can create a new thread NT in any cluster K'. This creation is initiated by the ''pthread_create'' system call.
     112 * The target cluster K' can be specified by the user application, using the CXY field of the pthread_attr_t argument. If the CXY is not defined by the user, the target cluster K' is selected by the kernel K, using the DQDT.
     113 * The target core in cluster K' can be specified by the user application, using the CORE_LID field of the pthread_attr_t argument. If the CORE_LID is not defined by the user, the target core is selected by the target kernel K'.
    114114
    115 If the target cluster M is different from the client cluster, the cluster K send a RPC_THREAD_USER_CREATE request to cluster M. The argument is a complete structure pthread_attr_t (defined in the ''thread.h'' file in ALMOS-MK), containing the PID, the function to execute and its arguments, and optionally, the target cluster and target core. This RPC should return the thread TRDID.
     115If the target cluster K' is different from the client cluster K, the cluster K send a RPC_THREAD_USER_CREATE request to cluster K'. The argument is a complete structure pthread_attr_t (defined in the ''thread.h'' file in ALMOS-MK), containing the PID, the function to execute and its arguments, and optionally, the target cluster and target core. This RPC should return the thread TRDID.
    116116
    117  * If the target cluster M does not contain a copy of the P process descriptor, the kernel M creates a process descriptor copy from the reference P process descriptor, using a remote_memcpy(), and using the cluster_get_reference_process_from_pid() to get the extended pointer on reference cluster. It allocates memory for the associated structures GPT(M,P), VSL(M,P), FDT(M,P).  These structures being used as read-only caches will be dynamically filled by the page faults. This new process descriptor is registered in the COPIES_LIST and in the LOCAL_LIST.
    118  * When the local process descriptor is set, the kernel M select the core that will execute the new thread, allocates a TRDID to this thread, creates the thread descritor, and registers it in the local process descriptor, and in the selected core scheduler.
     117 * If the target cluster K' does not contain a copy of the P process descriptor, the kernel K' creates a process descriptor copy from the reference P process descriptor, using a remote_memcpy(), and using the cluster_get_reference_process_from_pid() to get the extended pointer on reference cluster. It allocates memory for the associated structures GPT(M,P), VSL(M,P), FDT(M,P).  These structures being used as read-only caches will be dynamically filled by the page faults. This new process descriptor is registered in the COPIES_LIST and in the LOCAL_LIST.
     118 * When the local process descriptor is set, the kernel K' select the core that will execute the new thread, allocates a TRDID to this thread, creates the thread descritor, and registers it in the local process descriptor, and in the selected core scheduler.
    119119
    120120== __5) Thread destruction__ ==
    121121
    122 The 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 be caused by the thread T itself, executing the ''pthread_exit()'' sys call to suicide. Finally, it can be caused by the ''exit()'' or ''kill()'' syscalsl requesting the destruction of all threads of a given process.   
     122The destruction of an user thread T can be caused by another thread K, executing  the ''pthread_cancel()'' sys call requesting the target thread T to stop execution. It can be caused by the thread T itself, executing the ''pthread_exit()'' sys call to suicide. Finally, it can be caused by the ''exit()'' or ''kill()'' syscalsl requesting the destruction of all threads of a given process.   
    123123
    124 The unique method to destroy a thread is to set the THREAD_FLAG_REQ_KILL or THREAD_FLAG_REQ_EXIT flags in the ''flags'' field of the thread descriptor. The thread will be asynchronously deleted by the scheduler at the next scheduling point.
    125 It detach the thread from the scheduler, detach the thread from the local process descriptor, and releases the memory allocated to the thread descriptor. The destruction request can be done by the ''target'' thread itself (for an exit), or it can be done by another ''killer'' thread (for a kill).
     124The unique method to destroy a thread is to call the '''thread_kill()''' function, that set the THREAD_FLAG_REQ_DELETE in the ''flags'' field of the target thread descriptor. The thread will be asynchronously deleted by the scheduler at the next scheduling point,
     125that calls the ''thread_destroy()'' function. This function detach the thread from the scheduler, detach the thread from the local process descriptor, and releases the memory allocated to the thread descriptor. The '''thread_kill(''') function can be called by the ''target'' thread itself (for an exit), or it can be done by another ''killer'' thread (for a kill).
    126126
    127127The main thread (i.e. the thread 0 in the process owner cluster) is a special case, because the main thread of a given process can only be deleted (i.e. marked for delete) by the parent process main thread executing the sys_wait() scale (see section [6] below).   
     
    131131The scenario is rather simple when the target thread is not running in ATTACHED mode.
    132132The killer thread (that can be the target thread itself for an exit) call the thread_kill() function that does the following actions: 
    133  * the killer thread  sets the BLOCKED_GLOBAL bit in the target thread ''blocked'' field,
    134  * for an exit, the killer thread sets the THREAD_FLAG_REQ_EXIT bit in the target thread ''flags'' field,
    135  * for a kill, the killer thread sets the THREAD_FLAG_REQ_KILL bit in the target thread ''flags'' field,
     133 * the killer thread  sets the THREAD_BLOCKED_GLOBAL bit in the target thread ''blocked'' field,
     134 * the killer thread sets the THREAD_FLAG_REQ_DELETE bit in the target thread ''flags'' field,
    136135 * the killer thread returns without waiting the actual deletion.
    137136
     
    146145=== 5.2) thread running in ATTACHED mode ===
    147146
    148 The thread destruction is more complex if the target thread T is running in ATTACHED mode, because another - possibly remote - J thread, executing the ''pthread_join'' system call, must be informed of the termination of thread T. As the ''thread_kill()'' function, executed by the killer thread K, and the ''sys_thread_join()'', 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.
     147The thread destruction is more complex if the target thread T is running in ATTACHED mode, because another joining thread J, executing the ''pthread_join()'' system call, must be informed of the termination of thread T. As the ''thread_kill()'' function, executed by the killer thread K, and the ''sys_thread_join()'', 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.
    149148
    150 Therefore, the destruction mechanism can involve three threads: the target thread T, the killer thread K, and the joining thread J:
     149This destruction mechanism can involve three threads: the target thread T, the killer thread K, and the joining thread J:
    151150
    152 It 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 T thread (only used for an exit); the ''join_xp'' field contains an extended pointer on the first arrived thread. It uses also two specific THREAD_FLAG_JOIN_DONE and THREAD_FLAG_KILL_DONE flags in the thread descriptor ''flags'' field, and one specific blocking bit THREAD_BLOCKED_JOIN, in the ''blocked'' field.
     151It uses three specific fields in the thread descriptor: the ''join_lock'' field is a remote_spin_lock; the ''join_value'' field contains the termination status returned by the T thread; the ''join_xp'' field contains an extended pointer on the first arrived thread. It uses also two specific THREAD_FLAG_JOIN_DONE and THREAD_FLAG_KILL_DONE flags in the thread descriptor ''flags'' field, and one specific blocking bit THREAD_BLOCKED_JOIN, in the ''blocked'' field.
    153152
    154153 * Both the killer thread K, executing the thread_kill() 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).