Re: race condition

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

 



thank you.


i did like that.
here wht is the use of schedule() in this case?
Any way after the certain time thread2 is executed.

 



On Wed, 2005-09-21 at 18:40 +0500, Fawad Lateef wrote:
> On 9/21/05, Fawad Lateef <fawadlateef@xxxxxxxxx> wrote:
> > On 9/21/05, raja <vnagaraju@xxxxxxxxxxxx> wrote:
> > > Hi,
> > >    I am trying to trace the race condition by creating 2 threads in
> > > kernel space.   One thread incriments a global value and other
> > > decrements that value.
> > > But I am unable to trace the race condition.
> > > I am listing my code.Will you please help me.
> > >
> > >
> > > static int __init init_module_atomic(void);
> > > static void __exit exit_module_atomic(void);
> > >
> >
> > No need for the above declaration ..........
> >
> > > int value=0;
> >
> > Can change this to unsigned long value  .........
> >
> > >
> > > int thread_function_1(void * data)
> > > {
> > >         printk("Entered into Thread 1\n");
> > >         int i;
> > >         for(i=0;i<1000;i++)
> > >         {
> >
> > Can change this loop to for( ; ; ) to get the result more properly
> >
> > >                 udelay(1000);
> >
> > Change this to schedule();
> >
> > >                 value++;
> > >                 printk("Value Is : %d\t",value);
> > >         }
> > >         printk("Exited From Thread 1\n");
> > >         return 0;
> > > }
> > >
> > > int thread_function_2(void * data)
> > > {
> > >         printk("Entered into Thread 2\n");
> > >         int i;
> > >         for(i=0;i<1000;i++)
> > >         {
> >
> > Change to for ( ; ; )
> >
> > >                 udelay(100);
> >
> > change to schedule()
> >
> > >                 value--;
> > >                 printk("Value Is : %d\t",value);
> > >         }
> > >         printk("Exited From Thread 2\n");
> > >         return 0;
> > > }
> > >
> >
> > In your code you won't be able to see just as your thread_1 terminates
> > quickly before starting thread_2 and udelay is stalling the whole CPU
> > and won't allow CPU to do other stuffs, so changing it to schedule()
> > will give you better result ...........
> >
> 
> And also do kill/send signals to your thread for killing ........ so
> that it wont result in seg-fault if you remove your module ........
> for the case mentioned above by me .....
> 
> 
> --
> Fawad Lateef
> 
> --
> 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