Messages in this thread | | | Date | Fri, 13 Jun 2008 18:46:05 +0400 | From | Oleg Nesterov <> | Subject | Re: [PATCH 1/2] workqueues: implement flush_work() |
| |
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.
| |