From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f5392,b2d3b08d2996d5d9 X-Google-Attributes: gidf5392,public X-Google-Thread: fa528,b2d3b08d2996d5d9 X-Google-Attributes: gidfa528,public X-Google-Thread: 108717,b2d3b08d2996d5d9 X-Google-Attributes: gid108717,public X-Google-Thread: 1103af,b2d3b08d2996d5d9 X-Google-Attributes: gid1103af,public X-Google-ArrivalTime: 2004-02-26 04:37:23 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-05!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!uninett.no!news.net.uni-c.dk!not-for-mail From: Kasper Dupont Newsgroups: comp.unix.tru64,comp.os.linux.misc,comp.os.linux.development.system,comp.programming Subject: Re: User/Kernel Level Threads Date: Thu, 26 Feb 2004 13:37:16 +0100 Organization: daimi.au.dk Message-ID: <403DE87C.8384B493@daimi.au.dk> References: NNTP-Posting-Host: horse06.daimi.au.dk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.net.uni-c.dk 1077798360 31037 130.225.18.246 (26 Feb 2004 12:26:00 GMT) X-Complaints-To: usenet@news.net.uni-c.dk NNTP-Posting-Date: Thu, 26 Feb 2004 12:26:00 +0000 (UTC) X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.4.20-24.9smp i686) X-Accept-Language: en Xref: archiver1.google.com comp.unix.tru64:11232 comp.os.linux.misc:17350 comp.os.linux.development.system:2884 comp.programming:12443 Anne wrote: > > Hello, > > I am confused about User level Thread /Kernel Level Threads. Could you > please look at my following questions? Many thanks for your time > > 0- With Kernel Level thread, will the thread run on Kernel mode? > that's what i have read, thread (user) code so can run on the kernel > space, that's look very dangerous for me! I think part of the confusion comes from the fact, that the term "kernel threads" have been used about two different things. If a user mode program needs to use threads, they can either be implemented in user mode or be a feature offered by the kernel. The later have been called kernel threads. In Linux a handfull of the threads on the system will be a part of the kernel handling various kernel tasks, they are also called kernel threads, but are something completely different from the other kernel threads. When a user mode program needs threads, the two possibilities each have advantages and disadvantages. Threads implemented in user mode have the advantage, that they can be used even if the kernel doesn't offer any threading. And thread switching can be very fast. Except from those two points, threads implemented in user mode have only disadvantages. Threads implemented in user mode will not allow more than one thread to run at any time even if there are multiple CPUs. And even worse, if a thread is blocked in a system call, that thread will still occupy the process, so no other thread can execute because the process is sleeping. I have heard of hybrid user/kernel mode thread implementations. But they have got to be very complicated, and I doubt they have any major advantages over an implementation 100% in kernel mode. The only real advantage of user mode threads when kernel support for threads exists is the overhead for switching between two threads. And that is only significant if your program requires a lot of switches between threads. In Linux a lot of work have been done to keep the overhead for switching between threads low. From the kernel's point of view, the only thing special about threaded programs compared to non-threaded programs, is the fact that multiple user tasks with same virtual memory space exists. And it will use this knowledge to do 1) Lazy switching, which means only switch memory map when it is strictly necesarry. 2) Give tasks with same virtual memory space as the last used slightly higher priority when picking the next task to be scheduled. I have not heard about other systems that have made the same effort to improve threading performance. I haven't seen any comparisions between threads using the Linux kernel, and threads implemented in user space, so I don't know if there is any significant difference in switching overhead. -- Kasper Dupont -- der bruger for meget tid paa usenet. For sending spam use mailto:aaarep@daimi.au.dk /* Would you like fries with that? */