p->clear_child_tid = (clone_flags & CLONE_CHILD_CLEARTID) ? child_tidptr: NULL; When the process terminates,13 0 is written to the address defined in clear_child_tid.14 kernel/fork.c void mm_release(struct task_struct *tsk, struct mm_struct *mm) {

if (tsk->clear_child_tid

&& atomic_read(&mm->mm_users) >1) {

tsk->clear_child_tid = NULL;

put_user(0, tidptr);

12put_user is used to copy data between kernel address space and user address space as discussed in Chapter 4.

13Or, more accurately, when it automatically frees its memory management data structures using mm_release at process termination.

14The condition mm->mm_users > 1 means that the memory management data structure must be used by at least one other process in the system. The current process is therefore a thread in the classical sense — it takes its address space from another process and has just one control flow.

In addition, sys_futex, a fast userspace mutex, is used to wake processes waiting for this event, namely, the end of the thread.

The above flags can be used from within userspace to check when threads are generated and destroyed in the kernel. clone_child_settid and clone_parent_settid are used to check when a thread is generated; clone_child_cleartid is used to pass information on the death of a thread from the kernel to userspace. These checks can genuinely be performed in parallel on multiprocessor systems.

Continue reading here: Kernel Threads

Was this article helpful?

0 0