Re: List of Processes

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

 



On Fri, Jul 02, 2004 at 02:42:44 +0000, manish regmi wrote:
> 
> >one small doubt, shouldn't we be acquiring a lock while iterating over
> >all the tasks ?
> >
> >anupam
> >
> >> for_each_task(p)
> >> {
> >> ...
> >> }
> >>
> >> You will each task's descriptor on p on each loop. The first one will be
> >> that of init. You will automatically break from loop when you finish
> >> traverse through all tasks.
> >> Actually a circular list.
> >>
> >> #define for_each_task(p) \
> >>         for (p = &init_task ; (p = p->next_task) != &init_task ; )
> >>
> >> regards manish
> >>
> 
> No, Lock is unnecessary here,
> we are not manipulating the list, just following the link.
> Lock is necessary if you add or remove from the list.

WRONG! Obviously, read across write is an error. Usualy a fatal one.
Just imagine that you are in the middle of the list and someone unlinks
the element you hold.  If you have data, that need locking, they need
locking for read too (sans some dirty ordering tricks).

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>

Attachment: signature.asc
Description: Digital signature


[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