significance of read_un/lock(&tasklist_lock)

Go To StackoverFlow.com

1

While following path for wait system call, noticed that before calling do_wait_thread we get hold of tasklist_lock. I am trying to understand the significance of tasklist_lock & where its appropriate to use.

716        read_lock(&tasklist_lock);
1717        tsk = current;
1718        do {
1719                retval = do_wait_thread(wo, tsk);
1720                if (retval)
1721                        goto end;
1722
1723                retval = ptrace_do_wait(wo, tsk);
1724                if (retval)
1725                        goto end;
1726
1727                if (wo->wo_flags & __WNOTHREAD)
1728                        break;
1729        } while_each_thread(current, tsk);
1730        read_unlock(&tasklist_lock);

I looked at the declaration of tasklist_lock, It is as follows.

/*
 251 * This serializes "schedule()" and also protects
 252 * the run-queue from deletions/modifications (but
 253 * _adding_ to the beginning of the run-queue has
 254 * a separate lock).
 255 */
 256 extern rwlock_t tasklist_lock;
 257 extern spinlock_t mmlist_lock;

I am not able to understand where we should use this. Can you please let me know about it. Appreciate your help.

2012-04-05 00:41
by vindyz


2

The loop iterates over each thread of the current task. Holding the tasklist lock ensures that none of those threads disappear while the loop is running.

2012-04-05 02:32
by caf
Ads