Re: [PATCH 1/2] kthread_create

Davide Libenzi
2004-01-04T04:55:58Z

On Sat, 3 Jan 2004, Davide Libenzi wrote:

> On Sun, 4 Jan 2004, Rusty Russell wrote:
>
> > In message <Pine.LNX.4.44.0401031021280.1678-100000@bigblue.dev.mdolabs.com> you write:
> > > Rusty, I took a better look at the patch and I think we can have
> > > per-kthread stuff w/out littering the task_struct and by making the thing
> > > more robust.
> >
> > Except sharing data with a lock is perfectly robust.
> >
> > > We keep a global list_head protected by a global spinlock. We
> > > define a structure that contain all the per-kthread stuff we need
> > > (including a task_struct* to the kthread itself). When a kthread starts it
> > > will add itself to the list, and when it will die it will remove itself
> > > from the list.
> >
> > Yeah, I deliberately didn't implement this, because (1) it seems like
> > a lot of complexity when using a lock and letting them share a single
> > structure works fine and is even simpler, and (2) the thread can't
> > just "do_exit()".
> >
> > You can get around (2) by having a permenant parent "kthread" thread
> > which is a parent to all the kthreads (it'll get a SIGCHLD when
> > someone does "do_exit()"). But the implementation was pretty ugly,
> > since it involved having a communications mechanism with the kthread
> > parent, which means you have the global ktm_message-like-thing for
> > this...
>
> You will lose in any case. What happens if the thread does do_exit() and
> you do kthread_stop() after that?
> With the patch I posted to you, the kthread_stop() will simply miss the
> lookup and return -ENOENT.

Nope, we are screwed in any case. Is it really important to give the
ability to do do_exit() for kthreads? I mean, why a simple return would
not work?

- Davide