From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: ffc1e,7eb0575470192e20 X-Google-Attributes: gidffc1e,public X-Google-Thread: 11035d,7eb0575470192e20 X-Google-Attributes: gid11035d,public X-Google-Thread: 115614,7eb0575470192e20 X-Google-Attributes: gid115614,public X-Google-Thread: fee84,7eb0575470192e20 X-Google-Attributes: gidfee84,public From: wnl@groupsys.com (William LeFebvre) Subject: Re: Understanding threads in Unix Date: 1998/09/28 Message-ID: <6umuaf$aeu$1@paxfeed.eni.net>#1/1 X-Deja-AN: 395497660 References: <360F04C1.ECAD5E9@iname.com> Organization: Group sys Consulting Newsgroups: comp.unix.aix,comp.unix.solaris,comp.unix.osf.osf1,comp.programming.threads In article <360F04C1.ECAD5E9@iname.com>, lo tek wrote: >>>From what I understand on NT, a new thread is different from a new >process in that a new thread gets its own stack but not its own heap. What's a heap? :-) In Unix, multiple threads execute in the same virtual memory space. They each have their own execution context (registers including PC and stack pointer) but they all share the same virtual memory space. Processes have separate memory spaces as well as execution contexts. >This means it's faster to initialize a new thread instead of a new >process. That's correct (in general). It also takes fewer resources. >The advantage is that, for example, a web server only uses new >threads to handle each request, instead of "blocking" requests and using >new processes. Well, the request wouldn't explicitly block. Instead it would have to wait as a new process was created, or as the request was dispatched to a waiting process (which may then have to be paged in). >How do AIX and Solaris compare in this regard? If neither has threads, >or neither has many apps that use threads, is this a performance >problem? Certainly I'm not suggesting NT would outperform. :) If both >have threads, which is more stable? Also, if an OS doesn't have threads, >an app may wish to emulate a threaded >environment, forcing each vendor to recreate threading which is probably >not trivial, and therefore error-prone. Okay, there's threads and there's kernel entities. A thread is a virtual object, but a kernel entity is a specific OS's mechanism for implementing multiple contexts in a single process. In Solaris these are called lightweight processes. You *must* treat these two items separately. It is true that threads can be implemented with any sort of API. There is a POSIX standard threads api called "pthreads" and it is very widely deployed across many Unix variants. Before pthreads, some vendors did implement their own threads mechanism, and it was quickly headed to the chaotic world you evisioned. But everyone now is moving towards pthreads. This is a good thing. How a pthreads thread is mapped on to a kernel entity is completely up to the OS. Those systems which have no support for kernel-based threading have no choice but to implement threads in a software library. They can do this and still retain the pthreads semantics. Those systems which have the ability may choose to map threads to kernel entities one-to-one. But the better systems implement 2-level or many-to-few: threads are bound to and unbound from kernel entities as needed. This is conceptually similar to how virtual pages are mapped to physical pages. One kernel entity (LWP) may handle s variety of threads throughout its lifetime. For more info, read my Performance Computing column on Threaded Programming. It was published in the September 1998 edition. Visit: http://www.performancecomputing.com/columns/daemons/9809.shtml Better yet, get Butenhof's book. -- William LeFebvre Group sys Consulting +1 770 813 3224