Re: Threads in 2.6.x kernel

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

 



On Fri, Jul 23, 2004 at 01:19:00 -0400, RSudharsanan@xxxxxxxxxxxxxx wrote:
> 
> 
> 
> 
> >>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.
> 
> 
> I have a doubt regarding the usage of complete_and_exit
> it makes use of a completion structure.
> 
> I am initialising it with
> init_completion() at init starting the thread and
> Wait_for_completion() at exit module for waiting for the thread
> a complete_and_exit() i am using at thread and i get the signal sigterm
> using signal_pending,...
> But is it not enough to just return a zero from the thread?.Is it just a
> synchronisation mechanism like waitqueue??..

Yes. Completion is similar to semaphore. You set the counter, then each
complete() decrements it and wait_for_completion waits until it becomes
zero.

The reason to use it is, that you must be sure, that the thread is not
running before you exit from module_done() and let the code be released
from memory. And since you are not the parent (init is parent and you
are in the rmmod process), you can't simply wait() for it.

-------------------------------------------------------------------------------
						 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