lkml.org 
[lkml]   [2009]   [Dec]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Warn people about flush_scheduled_work()
Hello, Alan Stern.

On 12/15/2009 06:33 AM, Alan Stern wrote:
> You've spent some time working on the workqueue implementation, right?
> I'd like to add comments or kerneldoc warning people about how
> dangerous it can be to use flush_scheduled_work() and related
> functions. Something like this:
>
> Think twice before calling this function! It's very easy
> to get into trouble if you don't take great care. Either
> of the following situations will lead to deadlock:
>
> Your code is running in the context of a scheduled
> work routine.
>
> Your code or its caller holds a lock needed by
> one of the work items currently on the workqueue.
>
> Since you generally don't know who your caller is, what locks
> it holds, or what locks are needed by the items on the
> workqueue, avoiding these situations is quite difficult.

I think both problems can be detected by lockdep, right? So, they
aren't that difficult to detect.

> Consider using cancel_work_sync() or cancel_delayed_work_sync()
> instead. In most situations they will accomplish what you
> need.
>
> Does this sound like a good idea? Certainly flush_scheduled_work()
> is used in places where it shouldn't be.

Yeah, recommending more work-specific constructs definitely would be
better. It's bad that we can't recommend the use of flush_work() as
it doesn't do cross-cpu flushing. Maybe that needs explanation too.

> If comments like this are added, where do you think would be a good
> place to put them?

DocBook comment on top of each function, maybe?

Thanks.

--
tejun


\
 
 \ /
  Last update: 2009-12-14 23:41    [W:0.096 / U:1.492 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site