From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII X-Google-Thread: f5392,b2d3b08d2996d5d9 X-Google-Attributes: gidf5392,public X-Google-Thread: fa528,b2d3b08d2996d5d9 X-Google-Attributes: gidfa528,public X-Google-Thread: 1103af,b2d3b08d2996d5d9 X-Google-Attributes: gid1103af,public X-Google-Thread: 108717,b2d3b08d2996d5d9 X-Google-Attributes: gid108717,public X-Google-ArrivalTime: 2004-02-25 14:12:14 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!wn11feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!not-for-mail From: Nick Landsberg Reply-To: hukolau@NOSPAM.att.net User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 X-Accept-Language: en-us, en, ru MIME-Version: 1.0 Newsgroups: comp.unix.tru64,comp.os.linux.misc,comp.os.linux.development.system,comp.programming Subject: Re: User/Kernel Level Threads References: <403d1014.1252629859@news.individual.net> In-Reply-To: <403d1014.1252629859@news.individual.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Message-ID: <259%b.93031$hR.1854628@bgtnsc05-news.ops.worldnet.att.net> Date: Wed, 25 Feb 2004 22:12:14 GMT NNTP-Posting-Host: 12.75.194.2 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1077747134 12.75.194.2 (Wed, 25 Feb 2004 22:12:14 GMT) NNTP-Posting-Date: Wed, 25 Feb 2004 22:12:14 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.unix.tru64:11225 comp.os.linux.misc:17315 comp.os.linux.development.system:2878 comp.programming:12387 Alf P. Steinbach wrote: > * anne_dolly00@yahoo.co.uk (Anne) schriebt: >=20 >>=20 >>I am confused about User level Thread /Kernel Level Threads. >=20 >=20 > So was I when reading your question. But it's just a question of > terminology, so I plugged the term "kernel-level thread" into Guggle, > and out popped e.g. > >=20 >=20 > User-level threads: > * All thread management is done by the application. > * The kernel is not aware of the existence of threads. > * Thread switching does not require kernel mode privileges. > * Scheduling is application specific. >=20 > Kernel-level threads: > * Windows/NT and OS/2 are examples of this approach. > * Kernel maintains context information for the process and the thread= s. > * Switching between threads requires the kernel. >=20 >=20 > Now these definitions should of course not be read too literally. E.g.= > one can easily imagine a situation where not all thread management is d= one > by the application (so not user-level thread according to above), but w= here > switching between threads does not always require the kernel (so not ke= rnel- > level thread). Instead, I think the points are meant as "typical featu= res". >=20 >=20 >=20 >=20 >=20 >>Could you >>please look at my following questions? Many thanks for your time >>=20 >>0- With Kernel Level thread, will the thread run on Kernel mode? >=20 >=20 > No, not necessarily and not even usually, and it's not even necessarily= > meaningful to say that a "thread runs in kernel (protected) mode"; it w= ill > switch back and forth between privilege levels as it calls and returns = from > operating system API functions. >=20 >=20 It would probably be meaningful to say that certain kernels support thread scheduling on behalf of a process within the kernel scheduler. This implies that different threads may run on different CPU's if it is more than a single-CPU box. On those platforms which do not provide kernel support of thread scheduling, all threads run on the same CPU as the process (and if you're CPU bound, rather than I/O bound, threading buys you nothing). >=20 >=20 >>that's what i have read, thread (user) code so can run on the kernel >>space, that's look very dangerous for me! >=20 >=20 > Huh. Agree with the HUH! No way, no how, not over my dead body as a kernel hacker. >=20 >=20 >=20 >>does thread kernel mode means really that the threads code is mapped >>on the kernel space? >=20 >=20 > Huh. See above. Thread scheduling is supported by some kernels. I know of know implementation which maps user code into kernel space. (Doesn't mean there aren't any, just that I don't know of one.) >=20 > =20 > =20 >=20 >>1- Java for instance provides a package to manage Threads at the user >>level. >=20 >=20 > The threading support in Java can be user-level threads or kernel-level= > threads depending on the system the Java application is executed on. Y= ou > don't really need to know. Unless you're into real-time systems progra= mming, > in which case you'll probably not be using Java anyway... ;-) >=20 >=20 Depends on what you mean by "real time." :) I was once involved in a project review which was talking about "real time billing." It took me quite a while to digest that to them "real time" was "under 5 minutes" while all that time I was thinking in sub-milliseconds as the benchmark. >=20 >=20 >>If instead a user wants to implement threads at the kernel >>level which package should he/she use when working on >> >>1- Windows NT >> >>2- Linux >=20 >=20 > That depends mainly on the language, and less on the operating system. >=20 > For example, in C++ one might use Boost.Threads, in C one might use > PThreads, in Java the built-in Java threads. >=20 > =20 > =20 >=20 >>2- If the user writes multithreaded code using user level library, >>will these threads be automatically mapped (one to one or many to >>many) to kernel level threads? >=20 >=20 > That depends on the threading library the user is using, and also on > the operating system. >=20 >=20 >=20 >>Or it is up to the user to instruct this, if yes how? >=20 >=20 > That depends on the threading library the user is using, and also on > the operating system. >=20 >=20 >=20 >=20 >>3- If kernel level threads are supported, will the operating >>system schedule processes first and then threads or schedule directly >>threads. >=20 >=20 > That depends on the operating system and on the scheduler. >=20 >=20 >=20 >>If the latter case is assumed some processes may stave and >>others substantially favoured! >=20 >=20 > Huh. >=20 >=20 Now we are getting into something akin to "real-time". I presume the typo above meant "starve." As far as I am concerned, the usual kernel scheduling algorithms are not for mere mortals to understand. They are geared to a time-sharing environment where you are penalized (but not too much) for excessive CPU usage. It depends on the implementation, but as I remember (possibly incorrectly), once a process has been context switched out, it goes on a run-queue and this is maintained in FIFO order. (If the process or thread is blocked by a blocking system call, it does not go on the run queue until the blocking system call is satisfied). The FIFO ordering is a half-hearted way to avoid starvation. > =20 >=20 >>4- When threads are created, each thread ll be associated with a >>dedicated stack within the same process's address space. What >>mechanism and policy is followed to protect each thread stack from the >>other >=20 >=20 > Essentially there is very little protection between threads in the same= > process no matter what threading library or OS you're using, because th= e > main point of threads is to have very little overhead in context switch= es. >=20 > One alternative might be to use Light-Weight Processes (LWPs) in *nix, > but I don't know more about that than that some people have recommended= it. >=20 > Since you have cross-posted to a lot of *nix groups I expect you'll get= > a lot more information about that, or possibly that someone has fed me > some disinformation. >=20 >=20 >=20 >>Many thanks for your help >=20 >=20 --=20 =D1 "It is impossible to make anything foolproof because fools are so=20 ingenious" - A. Bloch