Linux work queues are meant to be kernel level threads with process context. I was trying to use it as an alternative to kthread which has no specific process context. But how do I pass data to work queue? work_struct has a data field which is of type atomic_long_t. I could not pass pointer to this field. How do I do it?
Also I could not find a single concrete example of work queue. Can you suggest one?
If you want to pass data to your work queue function, just embed the work_struct
structure inside your own data structure and use container_of
inside your work function to retrieve it.
As for a simple example, the kernel is full of it - just git grep work_struct
. You can look at drivers/cpufreq/cpufreq.c
(handle_update
function) for a simple example. The article below also embeds an example at the end, but it does not use container_of
and instead relies on the fact that the first member of a structure has the same address as its parent:
http://www.ibm.com/developerworks/linux/library/l-tasklets/index.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With