Re: [PATCH 1/2] workqueues: implement flush_work()

From: Oleg Nesterov
Date: Fri Jun 13 2008 - 10:44:14 EST


On 06/13, Oleg Nesterov wrote:
>
> Add the new helper, flush_work(work), which waits for the completion of the
> specific work_struct.
>
> By its nature it requires that this work must not be re-queued, and thus its
> usage is limited. For example, this code
>
> queue_work(wq, work);
> /* WINDOW */
> queue_work(wq, work);
>
> flush_work(work);
>
> is not right. What can happen in the WINDOW above is
>
> - wq starts the execution of work->func()
>
> - the caller migrates to another CPU
>
> now, after the 2nd queue_work() this work is active on the previous CPU, and
> at the same time it is queued on another.

To clarify, in the scenario above, flush_work() behaves correctly. It "flushes"
the result of the last queue_work() which is visible to the caller. We can add
another simple helper,

int flush_work_sync(work)
{
return flush_work(work) || wait_on_work(work);
}

but I think it is not needed.

In short: flush_work() should be use with care when it is really needed.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/