Re: How to create some threads running tha same function

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

 



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


_______________________________________________
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