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: 1103af,b2d3b08d2996d5d9 X-Google-Attributes: gid1103af,public X-Google-Thread: fa528,b2d3b08d2996d5d9 X-Google-Attributes: gidfa528,public X-Google-Thread: 108717,b2d3b08d2996d5d9 X-Google-Attributes: gid108717,public X-Google-ArrivalTime: 2004-02-25 13:37:50 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!news-FFM2.ecrc.net!fu-berlin.de!uni-berlin.de!a217-118-49-19.bluecom.NO!not-for-mail From: alfps@start.no (Alf P. Steinbach) Newsgroups: comp.unix.tru64,comp.os.linux.misc,comp.os.linux.development.system,comp.programming Subject: Re: User/Kernel Level Threads Date: Wed, 25 Feb 2004 21:37:47 GMT Message-ID: <403d1014.1252629859@news.individual.net> References: NNTP-Posting-Host: a217-118-49-19.bluecom.no (217.118.49.19) X-Trace: news.uni-berlin.de 1077745068 53618436 I 217.118.49.19 ([190004]) X-Newsreader: Forte Free Agent 1.21/32.243 Xref: archiver1.google.com comp.unix.tru64:11224 comp.os.linux.misc:17309 comp.os.linux.development.system:2877 comp.programming:12383 * anne_dolly00@yahoo.co.uk (Anne) schriebt: > > I am confused about User level Thread /Kernel Level Threads. 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. 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. Kernel-level threads: * Windows/NT and OS/2 are examples of this approach. * Kernel maintains context information for the process and the threads. * Switching between threads requires the kernel. 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 done by the application (so not user-level thread according to above), but where switching between threads does not always require the kernel (so not kernel- level thread). Instead, I think the points are meant as "typical features". > 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? 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 will switch back and forth between privilege levels as it calls and returns from operating system API functions. > that's what i have read, thread (user) code so can run on the kernel > space, that's look very dangerous for me! Huh. > does thread kernel mode means really that the threads code is mapped > on the kernel space? Huh. > 1- Java for instance provides a package to manage Threads at the user > level. The threading support in Java can be user-level threads or kernel-level threads depending on the system the Java application is executed on. You don't really need to know. Unless you're into real-time systems programming, in which case you'll probably not be using Java anyway... ;-) > 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 That depends mainly on the language, and less on the operating system. For example, in C++ one might use Boost.Threads, in C one might use PThreads, in Java the built-in Java threads. > 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? That depends on the threading library the user is using, and also on the operating system. > Or it is up to the user to instruct this, if yes how? That depends on the threading library the user is using, and also on the operating system. > 3- If kernel level threads are supported, will the operating > system schedule processes first and then threads or schedule directly > threads. That depends on the operating system and on the scheduler. > If the latter case is assumed some processes may stave and > others substantially favoured! Huh. > 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 Essentially there is very little protection between threads in the same process no matter what threading library or OS you're using, because the main point of threads is to have very little overhead in context switches. 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. 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. > Many thanks for your help