Can a work submitted to linux workqueue schedule itself

268 views Asked by At

PFB the pseudo code:

struct work_struct my_work;

my_wq = alloc_workqueue();

INIT_WORK(&my_work, worker_func);

void worker_func() {

  if (condition)
      queue_work(my_wq, my_work);

}

Is this allowed?

1

There are 1 answers

0
Tsyvarev On

Yes, it is perfectly allowed to re-submit a work while its function is executed.

It is also allowed to de-allocate the work structure which function is executed. Workqueue implementation is ready for that (kernel/workqueue.c):

It is permissible to free the struct work_struct from inside the function that is called from it, this we need to take into account for lockdep too...