Call flush_scheduled_work in the context of a work routine

Bogdan Bogush bogdan.s.bogush at gmail.com
Thu Apr 30 08:24:53 EDT 2020


The comment to flush_scheduled_work states that calling this function in
the context of a work routine will lead to deadlock. I think it means
following scenario:

static void
handler(struct work_struct *work)
{
    flush_scheduled_work();
}
static DECLARE_WORK(work, handler);
schedule_work(&work);


If this is true for system workqueue (system_wq) is it also applied to
custom workqueue? I want to wait for completion of the workqueues in
another workqueue. For example:

static void
handler(struct work_struct *work)
{
    struct work_data * data = (struct work_data *)work;
    flush_scheduled_work();
    kfree(data);
}
  wq = create_workqueue("wq_test");
  data = kmalloc(sizeof(struct work_data), GFP_KERNEL);
  INIT_WORK(&data->work, handler);
  queue_work(wq, &data->work);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20200430/21956627/attachment.html>


More information about the Kernelnewbies mailing list