Re: Threads in 2.6.x kernel

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

 



On Tue, Jul 20, 2004 at 02:29:33 -0400, RSudharsanan@xxxxxxxxxxxxxx wrote:
> hi,
>    What is the simplest way to create kernel threads in 2.6.x kernel.I got
> one for 2.4.x
> from http://www.scs.ch/~frey/linux/kernelthreads.html8

Hell, that mixes so many things that don't have anything to do with each
other.

> but the task queues are not implemented here.I suppose i have to go for

Task queues and kernel threads are one of them. They are completely
distinct things. Unfortunately it's not really obvious from that
example.

> Work queue interface
> Is it necessary first??? just for creating /stopping and killing threads.

kernel_thread() behaves exactly like clone() in userspace (but the flags
are like for fork). In fact, it calls the same code internaly. You pass
it a function that should run in it, it sets up a new task_struct
+ stack for it and runs it. When it ends, the thread exists. The thread
is a process, so it is scheduled like one (you must call schedule()
because kernel is not preemptive (2.6 can be, but may be compiled
without)). You must call kernel_thread in a process context, which
generaly means module_init(), syscall handler or another kernel thread.

Task queues are lists of functions that should be called from somewhere.
Work queues are similar, generalized.

You can use kernel threads without task/work queues and generaly it's
done so. Many modules simply spawn a kernel thread in init and the
thread then sits in a loop waiting on a wait_queue (which is
a synchronization primitive -- nothing to do with task/work queues) for
some task to do.

You can use task/work queues without kernel threads. There are many
places in kernel that run various task/work queues at different times.
There is also a generic work-queue running thread, whose services you
may use.

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