lkml.org 
[lkml]   [2008]   [Jun]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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.



\
 
 \ /
  Last update: 2008-06-13 16:47    [W:0.065 / U:0.244 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site