129 | | The unique method to destroy a thread is to call the '''thread_delete()''' function, that sets the THREAD_FLAG_REQ_DELETE bit in the ''flags'' field of the target thread descriptor. The thread will be asynchronously deleted by the scheduler at the next scheduling point. |
130 | | The scheduler calls the ''thread_destroy()'' function that detaches the thread from the scheduler, detaches the thread from the local process descriptor, and releases the memory allocated to the thread descriptor. The '''thread_delete()''' function can be called by the target thread itself (for an exit), or by another thread (for a kill). |
131 | | |
132 | | If the target thread is running in attached mode, the '''thread_delete()''' function synchronizes with the joining thread, waiting the actual execution of the [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/syscalls/sys_thread_join.c pthread_join()] syscall before marking the target thread for delete. |
133 | | |
134 | | If the target thread is the main thread (i.e. the thread 0 in the process owner cluster) the '''thread_delete()''' does not mark the target thread for delete, because this must be done by the parent process main thread executing the [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/syscalls/sys_wait.c wait()] syscall (see section [6] below). |
| 129 | The unique method to destroy a thread is to call the [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/kern/thread.c thread_delete()] function, that sets the THREAD_FLAG_REQ_DELETE bit in the ''flags'' field of the target thread descriptor. The thread will be asynchronously deleted by the scheduler at the next scheduling point. |
| 130 | The scheduler calls the [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/kern/thread.c thread_destroy()] function that detaches the thread from the scheduler, detaches the thread from the local process descriptor, and releases the memory allocated to the thread descriptor. |
| 131 | |
| 132 | If the target thread is running in attached mode, the [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/kern/thread.c thread_delete()] function synchronizes with the joining thread, waiting the actual execution of the [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/syscalls/sys_thread_join.c pthread_join()] syscall before marking the target thread for delete. |
| 133 | |
| 134 | If the target thread is the main thread (i.e. the thread 0 in the process owner cluster) the [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/kern/thread.c thread_delete()] function does not mark the target thread for delete, because this must be done by the parent process main thread executing the [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/syscalls/sys_wait.c wait()] syscall (see section [6] below). |