Re: How to create some threads running tha same function

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

 





On Thu, Sep 15, 2011 at 7:59 PM, Kristof Provost <kristof@xxxxxxxxxx> wrote:
On 2011-09-15 22:20:03 (+0800), Parmenides <mobile.parmenides@xxxxxxxxx> wrote:
>    I will try to test how to create kernel threads and have write a>       }


<snip>
 
You're passing the address of a stack variable (i) as data pointer.
That's not right, because as soon as you exit the kthread_init function
the data may be overwritten.

Also, even if you declare i as global to solve this issue, you would not get what you expect because all the threads you create get the _same_ address pointing to the same variable i. This variable will keep on incrementing in the background till all your threads are created and thus your threads will print the current value of i which is not what you expect.

You can pass the variable i as a _value_ directly instead of passing a pointer to solve this problem.

Kaustubh
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[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