lkml.org 
[lkml]   [2007]   [Apr]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From(Eric W. Biederman)
SubjectRe: [PATCH] kthread: Don't depend on work queues
DateWed, 11 Apr 2007 10:25:48 -0600
Oleg Nesterov <oleg@tv-sign.ru> writes:

> On 04/10, Eric W. Biederman wrote:
>>
>> +int kthreadd(void *unused)
>> +{
>> + /* Setup a clean context for our children to inherit. */
>> + kthreadd_setup();
>> +
>> + current->flags |= PF_NOFREEZE;
>> +
>> + for (;;) {
>> + wait_event(kthread_create_work,
>> + !list_empty(&kthread_create_list));
>> +
>> + spin_lock(&kthread_create_lock);
>> + while (!list_empty(&kthread_create_list)) {
>
> Do we need to check the condition under lock? We can miss an event,
> but then it will be noticed by wait_event() above.

We need to be certain there is something on the list before we remove
it. Otherwise we will start dereferencing bad pointers.

> IOW,
>
> for (;;) {
> wait_event(kthread_create_work,
> !list_empty(&kthread_create_list));
>
> while (!list_empty(&kthread_create_list)) {
> struct kthread_create_info *create;
>
> spin_lock(&kthread_create_lock);
> create = list_entry(kthread_create_list.next,
> struct kthread_create_info, list);
> list_del_init(&create->list);
> spin_unlock(&kthread_create_lock);
>
> create_kthread(create);
> }
> }

I guess since we are the only process to ever remove things from the
list that would be safe.

Eric

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

\
 
 \ /
  Last update: 2007-04-11 18:29    [from the cache]
©2003-2010