Changes between Version 77 and Version 78 of processus_thread


Ignore:
Timestamp:
Feb 24, 2018, 3:37:19 PM (4 years ago)
Author:
alain
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • processus_thread

    v77 v78  
    120120== __5) Thread destruction__ ==
    121121
    122 The destruction of a thread T running in cluster K can be caused by another thread K, executing  the thread_kill() function requesting the target thread to stop execution. It can also be caused by the thread T itself, executing the thread_exit() function to suicide.
     122The destruction of a thread T running in cluster K can be caused by another thread K, executing  the thread_kill() function requesting the target thread to stop execution. It can also be caused by the thread T itself, executing the thread_exit() function to suicide. It can also be caused by the sys_exit() or sys_kill() syscalsl requesting the destruction of all threads of a given process.   
    123123
    124124=== 5.1) thread kill ===
     
    151151== __6) Process destruction__ ==
    152152
    153 The destruction of process P can be caused by a sys_exit() system call executed by any thread of process P,  or by another process executing the sys_kill() system call. It can also be caused by a CtrlC signal typed on the process terminal. In all cases, the work must be done by a thread running in the owner cluster, because all process copies must be involved, and the list of copies is rooted in the owner cluster. It must be done by a RPC thread, because a thread cannot delete itself.
     153The destruction of a process P can be caused by a sys_exit() system call executed by the main thread of process P,  or by another process executing the sys_kill(SIGKILL) system call. It can also be caused by a CtrlC signal typed on the process terminal. In all cases, the work must be done for all process copies in all clusters, using the list of copies rooted in the owner cluster.
    154154
    155155=== 6.1 parent / children synchronization
    156156
    157 The process descriptors copies (I.e. other than the reference process descriptor) are simply deleted by the scheduler when the last thread of a given process in a given cluster is  deleted. The process descriptor copy is removed from the list of copies in the owner process cluster descriptor, and that's it.
     157The process descriptors copies (other than the process descriptor in owner cluster) are simply deleted by the scheduler when the last thread of a given process in a given cluster is  deleted. The process descriptor copy is removed from the list of copies in the owner process cluster descriptor, and the process copy disappears.
    158158
    159 But the process destruction in the owner cluster is more complex, because the child process destruction must be reported to the parent process when the parent process executes the blocking sys_wait() system call. Therefore, the child process destruction cannot be done before the parent calls the sys_wait() function. As the '''sys_wait()''' function, and the '''sys_kill() / sys_exit()''' function are executed by different threads running in different clusters, this requires a parent/child synchronization.
    160  
    161 After a sys-kill() or sys_exit(), all process threads and all process copies are immediately destroyed, but the process descriptor in owner cluster is kept in ''zombi'' state :  the main thread (i.e. thread 0 in process owner cluster) is not deleted until the sys_wait() syscall is executed by the parent process.  The synchronization uses the '''term_state'''  field in the child process descriptor, that contains the following informations :
    162  * the PROCESS_FLAG_KILL flag indicates that a KILL request has been received by the child; 
    163  * the PROCESS_FLAG_EXIT flag indicates that an EXIT  request has been made by the child; 
    164  * the PROCESS_FLAG_BLOCK flag indicates that a SIGSTOP signal has been received by the child;
     159But the process destruction in the owner cluster is more complex, because the child process destruction must be reported to the parent process when the parent process executes the blocking sys_wait() system call. Therefore, the child process destruction cannot be done before the parent calls the sys_wait() function. As the '''sys_wait()''' function, and the '''sys_kill() / sys_exit()''' function are executed by different threads running in different clusters, this requires a parent/child synchronization:
     160After a sys-kill() or sys_exit(), the process descriptor in owner cluster is kept in ''zombi'' state :  the main thread (i.e. thread 0 in process owner cluster) is not deleted until the sys_wait() syscall is executed by the parent process.  The synchronization uses the '''term_state'''  field in the child process descriptor, that contains the following informations :
     161 * the PROCESS_FLAG_KILL  indicates that a KILL request has been received by the child; 
     162 * the PROCESS_FLAG_EXIT indicates that an EXIT  request has been made by the child; 
     163 * the PROCESS_FLAG_BLOCK indicates that a SIGSTOP signal has been received by the child;
    165164 * the PROCESS_FLAG_WAIT flag indicates that a WAIT  request from parent has been received by the child and reported to parent.
    166  * moreover the exit() argument  is registered in the ''term_state'' field of the process descriptor.
     165 * moreover, for an exit(),  the exit() argument  is registered in this ''term_state'' field.
    167166
    168 The actual deletion of the process descriptor in owner cluster is done by the sys_wait() function that must be executed by the parent main thread (i.e. thread 0 in parent owner cluster). This sys_wait() function executes an infinite loop. At each iteration the parent scan all children owner descriptors. When it detects that one child terminated,
    169 it set the PROCESS_FLAG_WAIT in child descriptor, set the THREAD_FLAG_DELETE in the child main thread, and exit to report the child termination state to parent process. It is the responsibility of the parent process to re-enter the sys_wait() sys call for the other children. When the parent does not detect a terminated child at the end of an iteration, it deschedule without blocking. 
     167The actual deletion of the process descriptor in owner cluster is done by the sys_wait() function, that must be executed by the parent main thread (i.e. thread 0 in parent owner cluster). This sys_wait() function executes an infinite loop. At each iteration the parent scan all children owner descriptors. When it detects that one child terminated,
     168it set the PROCESS_FLAG_WAIT in child descriptor, set the THREAD_FLAG_DELETE in the child main thread, and exit to report the child termination state to parent process. It is the responsibility of the parent process to re-enter the sys_wait() syscall for the other children. When the parent process does not detect a terminated child at the end of an iteration, it deschedules without blocking. 
    170169
    171170
    172 === 6.2) detailed destruction scenario ===
     171=== 6.2) detailed exit scenario ===
    173172
    174  1. Both the sys_kill() or sys_exit() sys calls, use the rpc_process_make_kill_client(), to ask an RPC thread to execute the process_make_kill() function in the owner cluster (because a thread cannot delete itself).
    175  1. The  process_make_kill() function in owner cluster send a multicast and parallel RPC to all clusters containing a copy of the process. In each cluster, the process_block_threads() function set the BLOCKED_GLOBAL bit for all threads of the process. It returns only when all threads are blocked and descheduled.
    176  1. When the process_make_kill() function in owner cluster has received all expected responses to the first multicast RPC, it send another multicast and parallel RPC to all clusters containing a copy of the process. In each cluster, the process_delete_threads() function releases the memory allocated to all local threads but the process main thread (thread 0 in owner cluster). All process descriptors copies are destroyed, but the one in owner cluster.
    177  1. When the process_make_kill() function in owner cluster has received all expected responses to the second multi-cast RPC, it updates the owner cluster manager
    178  to remove the process from the set of owned processes.
    179  1. Finally, the process_make_kill() function synchronizes with the parent process, and the parent sys_wait() function delete the process descriptor in owner cluster.
     173This section describes the termination of a process caused by a sys_exit().
     174
     175 1. The sys_exit() syscall must be executed by the main thread of the calling process( i.e. thread 0 in owner cluster),
     176 1. The sys_exit() function calls the process_sigaction() function that send a multicast, parallel and non blocking RPC to all clusters containing at least one thread of the calling process, to block all process threads, but the main (calling) thread. This function returns only when all threads (but the main) are blocked and descheduled.
     177 1. The sys_exit() function calls again the process_sigaction() function that send another multicast, parallel and non blocking RPC to the same clusters, to mark for delete all process threads, but the main (calling) thread. The marked threads will be actually destroyed by the scheduler at the next scheduling point. The remote process descriptor copies are actually destroyed by the scheduler when the last thread in remote cluster is destroyed.
     178 1. The sys_exit() function set the PROCESS_TERM_EXIT flag in owner process descriptor to synchronize with the parent process, and deschedules.
     179 1. This main thread, and the process descriptor in owner cluster  will be actually destroyed by the scheduler when the parent process sys_wait() function marks this main thread for delete.
     180
     181=== 6.3) detailed kill scenario ===
     182
     183This section describes the termination of a target process caused by a sys_kill(  SIGKILL ).
     184 
     185 1. The sys_kill() syscali must be executed by the main thread of the target process OR by any thread of another process than the target process.
     186 1. The sys_kill() function calls the process_sigaction() function that send a multicast, parallel and non blocking RPC to all clusters containing at least one thread of the target process, to block all process threads, but the main thread. This function returns only when all threads (but the main) are blocked and descheduled.
     1871. The sys_kill() function calls again the process_sigaction() function that send another multicast, parallel and non blocking RPC to the same clusters, to mark for delete all process threads, but the main thread. The marked threads will be actually destroyed by the scheduler at the next scheduling point. The target process descriptor copies are actually destroyed by the scheduler when the last thread in remote cluster is destroyed.
     188 1. The sys_kill() function set the PROCESS_TERM_KILL flag in the target process descriptor in owner cluster to synchronize with its parent process, and returns.
     189 1. The target process main thread, and the target process descriptor in owner cluster  will be actually destroyed by the scheduler when the parent process sys_wait() function marks this main thread for delete.