How to create some threads running tha same function
Kristof Provost
kristof at sigsegv.be
Thu Sep 15 10:29:39 EDT 2011
On 2011-09-15 22:20:03 (+0800), Parmenides <mobile.parmenides at gmail.com> wrote:
> I will try to test how to create kernel threads and have write a
> kernel module which creates a number of kernel threads running the
> same function. But the results is somewhat confusing.
>
> static int kthread_init(void)
> {
> int i;
>
> for (i = 0; i < MAX_KTHREAD; i++){
> ktask[i] = kthread_run(my_kthread, &i, "mythread[%d]", i);
> }
> return 0;
> }
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.
The fact that it works in some cases is pure coincidence.
Regards,
Kristof
More information about the Kernelnewbies
mailing list