How to create some threads running tha same function

Kaustubh Ashtekar ksashtekar at
Fri Sep 16 00:56:56 EDT 2011

On Thu, Sep 15, 2011 at 7:59 PM, Kristof Provost <kristof at> wrote:

> On 2011-09-15 22:20:03 (+0800), Parmenides <mobile.parmenides at>
> wrote:
> >    I will try to test how to create kernel threads and have write a>
>   }

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

-------------- next part --------------
An HTML attachment was scrubbed...

More information about the Kernelnewbies mailing list