Re: Threads in 2.6.x kernel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jul 22, 2004 at 11:49:27 +0530, RSudharsanan@xxxxxxxxxxxxxx wrote:
> 
> hi,
>    thanks to Jan for the help it worked fine i was really confused with
> many data structures waitiqueue/wokqueue/taskqueue.Now I am able to create
> threads.But i have some more doubts
> 
> *How shall i kill the thread i created with kernel_thread
>       I tried using
>             send_sig(SIGKILL,thread_task,1);
>             thread_task i am initialising with
>             thread_task = current ;
>       when the thread starts.Is it the right way of killing the thread.
> But  even after killing i find the thread as <defunct> with the ps viewer
> under the application using the driver.

Especialy for modules, you must make sure the thread has exited before
you return from module_done(). And there is only one way to do it -- use
complete_and_exit() to end the thread and wait_for_completion() in
module_dome(). That means, that the thread must exit actively.

Now the question comes down to how to tell the thread to exit. There are
generaly two ways:
1) Have a flag somewhere. Wake up the thread (by setting it's state to
   running or using a waitqueue) and have it check that flag and
   complete_and_exit() if it's set.
2) Use a signal. You can send the thread a signal and it will cause it
   to wake up from interruptible sleep automaticaly. But you must check
   signal_pending() yourself and complete_and_exit() if appropriate bit
   is set. Normaly, signals are handled during return to userspace, but
   kernel threads never return to userspace. Thus you have to check for
   them manualy.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@xxxxxx>

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux