passing/sharing the data using workQueue in linux kernel


passing/sharing the data using workQueue in linux kernel



Please can anyone help me in understanding "Passing data(shared or private)" to workQueue ?



1: Declare a call back/work handler


static void sample_work_fn(struct work_struct *Wq)
{
...........
...........
}



2: fill in a work_struct structure (statically)


static DECLARE_WORK(sample_work, sample_work_fn);



3: Schedule a workqueue


static void samp_sysrq(int arg)
{
schedule_work(sample_work);
}



Here if I need to pass/share data using my work queue, how is it possible?





possible duplicate of How to use Linux Work Queue
– Benjamin Leinweber
Sep 28 '14 at 16:41





Sanumala, welcome to Stack Overflow. As my previous comment suggests, this question has already been answered in another post. Please see the link in the above comment. This site prefers to have as few duplicate questions as possible so it is likely this thread will be closed. Please do not take offense to this and treat it as a learning experience. Again, welcome!
– Benjamin Leinweber
Sep 28 '14 at 16:42






Thanks Benjamin,
– sanumala
Sep 29 '14 at 16:52




1 Answer
1



Thanks Benjamin,



I found the information in "Linux transfer parameter for function in DECLARE_WORK" is really straight forward and it really Helped me to understand. this links says



DECLARE_WORK is primarily for static work items, where no instance data is needed. You want INIT_WORK. Use this to initialize a work_struct that is a member of another structure (of your choosing), then use container_of in the callback to get the pointer to the containing structure. This container_of pattern is extremely common in the Linux kernel, so it's a good idea to get familiar with it!






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift