Thread (3 messages) 3 messages, 3 authors, 2011-09-16

How to create some threads running tha same function

From: Kristof Provost <hidden>
Date: 2011-09-15 14:29:39

On 2011-09-15 22:20:03 (+0800), Parmenides [off-list ref] 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help