On 5/19/07, Robert P. J. Day <rpjday@xxxxxxxxxxxxxx> wrote:
as a short demo of using a delayed work queue, i wrote the following module which, every second, just does a printk() to /var/log/messages, and stops when you unload it. ========================================================================== #include <linux/module.h> // for all modules #include <linux/init.h> // for entry/exit macros #include <linux/kernel.h> // for printk macros #include <linux/workqueue.h> static void work_func(struct work_struct *unused); static DECLARE_DELAYED_WORK(work, work_func); static int count ; static void work_func(struct work_struct *unused) { printk(KERN_INFO "yee ha timer, %d.\n", ++count); schedule_delayed_work(&work, HZ); } static int hi(void) { printk(KERN_INFO "Hello from timer.\n"); schedule_delayed_work(&work, HZ); count = 0 ; return 0; } static void bye(void) { printk(KERN_INFO "Goodbye from timer.\n"); cancel_delayed_work(&work); flush_scheduled_work(); } module_init(hi); module_exit(bye); MODULE_LICENSE("Dual BSD/GPL"); ======================================================================= the module works just fine, but i'm not sure if i'm closing down the work queue properly upon module unloading. note that i'm doing both: cancel_delayed_work(&work); flush_scheduled_work(); is it necessary to do both? and i've seen code that is even more careful to do: if (!cancel_delayed_work(&work)) flush_scheduled_work(); just in case the work callback function is still running on return from cancel_delayed_work().
Robert, i ran into this situation days back and i remember it worked fine for me. But at the same time if you observe closely, value returned by cancel_delayed_work(&work) is not checked at a lot of places in the kernel, why i have no idea? Perhaps because it always results in current work handler to complete(if it is in between). Saying that i guess why would you need flush_scheduled_work() then? Maybe you want to do a flush_workqueue() instead? Just to add while inquiring i also came to know that return value from queue_delayed_work() is also not checked at mostly all the places in the kernel.Another big WHY?? And just to add as a bonus novice doubt even del_timer() 's return value is not check at most of the places, another why?? Thoughts? Thanks --psr
what's the proper way to close this down? thanks. rday -- ======================================================================== Robert P. J. Day Linux Consulting, Training and Annoying Kernel Pedantry Waterloo, Ontario, CANADA http://fsdev.net/wiki/index.php?title=Main_Page ======================================================================== -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ
-- play the game -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ