I want to create an RTDM driver that uses a thread (rtdm_task_t) to perform a cyclic job. Although it's possible to start this thread (using rtdm_task_init) from the module_init code, I'm unsure of how I should terminate this thread.
I seem to have several options: 1. Just kill the thread with rtdm_task_destroy. This means that the thread should never block, except on rtdm_task_wait_period, or else it might be terminated on the blocking instruction and leave the hardware in an unknown state. 2. Use a stop variable, along with a semaphore to ensure that the thread has stopped. E.g.: volatile int stop_requested = 0; rtdm_sem_t sem; void the_thread(void *cookie) { while (!stop_requested) { /* Blocking may occur, due to calls to e.g. rtdm_read */ rtdm_task_wait_period(); } do_some_cleaning_up(); rtdm_sem_up(&sem); /* Release the pending module_exit */ } void __exit module_exit() { stop_requested = 1; rtdm sem_down(&sem); rtdm_sem_destroy(&sem); rtdm_task_destroy(&task); rtdm_unregister(); } However, this means I would issue a blocking call in Linux kernel context. To me, it seems that the whole Linux thread would be suspended, but I just tried this and it fails (segfault on sem_down and unusable system). Another question is if I still need to clean up (destroy) a task that has run to completion ? 3. Unload the module, set a variable as the one above (stop_requested) and leave the unregistering to the exiting thread. This seems ugly to me, and I also think that it would crash, as the Linux kernel will remove the program (including the thread code) from memory. So, in short, how do I wait in the module_exit ? Jeroen.
_______________________________________________ Xenomai-help mailing list Xenomai-help@gna.org https://mail.gna.org/listinfo/xenomai-help