Re: process traversal versus thread traversal

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On Fri, Apr 4, 2008 at 10:23 PM, Robert P. J. Day <rpjday@xxxxxxxxxxxxxx> wrote:

 i'm still a bit unclear on the linked list traversal of kernel
"tasks", given what i'm reading in some documentation someone sent me,
and i'm thinking that this doc isn't quite correct.

 the bullet points in this doc (whose identity shall remain
concealed, to protect the innocent :-):

 * Only default threads linked by tasks list_head
 * Other threads not seen by for_each_process() macro
 * Visible to do_each_thread() macro

 now, if by "default thread" the author means the thread group
leader, this doesn't seem right, does it?  that clearly suggests that
only each thread group leader is on the system-wide task list.  i
thought someone on this (mailing) list had already taken the position
that, no, *all* threads need to be on the system-wide task list for
proper scheduling.

 and it gets more confusing if you examine the definition of those
macros in sched.h:

====================
#define next_task(p) \
       list_entry(rcu_dereference((p)->tasks.next), struct task_struct, tasks)

#define for_each_process(p) \
       for (p = &init_task ; (p = next_task(p)) != &init_task ; )

/*
 * Careful: do_each_thread/while_each_thread is a double loop so
 *          'break' will not work as expected - use goto instead.
 */
#define do_each_thread(g, t) \
       for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do

this is a double loop

#define while_each_thread(g,t) \
while ((t = next_thread(t) != g)
 
this leads to the conclusion.....the document ur reading document is correct.




====================

 if i read this correctly, for_each_process() starts at the init task
and simply traverses the system-wide task list, right?  but doesn't
do_each_thread() appear to do the same thing?  that second macro does
have an extra parameter but the logic appears to be identical, doesn't
it?   it just starts at init_task and follows the next pointer.

 is there something here i'm missing?  is this due to some historical
cruft still lying around?  thanks.

rday
--

========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
   Have classroom, will lecture.

http://crashcourse.ca                          Waterloo, Ontario, CANADA
========================================================================

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ




cheers,
Nikhil


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux