RE: List of Processes

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

 



Lock is required even if we are reading global data structure.

Think about the scenario when there are two processes using the same
global data structure (linked list). Let's say process1 is reading the
Data Structure and process2 is modifying the Data Structure. While
linked process1 is in between the linked list, process2 deletes some of
the nodes from list on which process1 is currently pointing. In this
case the list is corrupted and process1 will not be able to go thru the
whole list.

It's really imp to lock any global data structure before either reading
or modifying it.

Thanks & Regards,
Gaurav Dhiman


-----Original Message-----
From: kernelnewbies-bounce@nl.linux.org
[mailto:kernelnewbies-bounce@nl.linux.org] On Behalf Of manish regmi
Sent: Friday, July 02, 2004 8:13 AM
To: anupam.kapoor@gmail.com
Cc: so_usp@yahoo.com.br; kernelnewbies@nl.linux.org
Subject: Re: List of Processes


>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.

regards manish

_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*  
http://join.msn.com/?page=features/junkmail


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[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