From: omgalvan.86@gmail.com (Martin Galvan) Date: Tue, 18 Jul 2017 13:00:11 -0300 Subject: kthread_stop always returning -EINTR? Message-ID: <1500393611-6621-1-git-send-email-martingalvan@sourceware.org> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org Hi everyone! I'm doing a bit of testing on the Linux kthread functions, and have the following module: #include #include #include #include #include #include MODULE_LICENSE("GPL"); int function(void *data) { printk(KERN_DEBUG "CPU: %u\n", smp_processor_id()); do_exit(0); /* Not sure if this is ok */ } /* Function executed upon loading driver */ int __init init_module(void) { unsigned int cpu; printk(KERN_DEBUG "init\n"); for_each_present_cpu(cpu) { struct task_struct *thread = kthread_create(function, NULL, "Thread %u", cpu); if (!IS_ERR(thread)) { int result; /* Bind the thread to the current core */ kthread_bind(thread, cpu); /* Start the thread */ wake_up_process(thread); /* Wait for the thread function to complete */ result = kthread_stop(thread); printk(KERN_DEBUG "Thread %u stopped with result %d\n", cpu, result); } else { printk(KERN_ALERT "Could not create a thread bound to core number %u\n", cpu); break; } } return 0; } /* Function executed when unloading module */ void cleanup_module(void) { printk(KERN_DEBUG "exit\n"); } >From what I understood, I should be able to see all the "CPU: ..." prints before init_module ends. However, kthread_stop is always returning -EINTR, as if wake_up_process wasn't actually being called. What am I doing wrong? (Please CC me directly when you answer this)