From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f678f,8e9b885446835ab4 X-Google-Attributes: gidf678f,public X-Google-ArrivalTime: 1994-11-09 13:52:34 PST Path: nntp.gmd.de!newsserver.jvnc.net!news.cac.psu.edu!news.pop.psu.edu!hudson.lm.com!godot.cc.duq.edu!news.duke.edu!news.mathworks.com!hookup!news.moneng.mei.com!uwm.edu!math.ohio-state.edu!cis.ohio-state.edu!news.sei.cmu.edu!bb3.andrew.cmu.edu!cantaloupe.srv.cs.cmu.edu!abh From: Andrew Hastings Newsgroups: comp.unix.osf.misc Subject: Re: errno and DCE and threads Date: 9 Nov 1994 20:05:47 GMT Organization: Transarc Corp., Pittsburgh Message-ID: <39ra2r$3fs@cantaloupe.srv.cs.cmu.edu> References: <39lsjk$lrf@clam.hi.com> <39o694$6a0@cantaloupe.srv.cs.cmu.edu> NNTP-Posting-Host: m.gp.cs.cmu.edu Originator: abh@M.GP.CS.CMU.EDU In article sp@albion.engr.sgi.com (Simon Patience) writes: >In article <39o694$6a0@cantaloupe.srv.cs.cmu.edu>, Andrew Hastings writes: >|> Since you're productizing DCE, you can change the DCE thread >|> implementation. Record errno along with the hardware registers in your >|> thread context. When you switch threads, switch errno values. > >Why you would want to waste a valuable register on errno is beyond me, keeping >the thread id in a register would be sensible as you access it frequently but >errno? Errno is best kept in thread private data. By thread private I don't mean >inaccessible to other threads, just not used by them. Who said anything about putting errno in a register? The original poster wanted to know how to maintain a thread-specific errno for thread-naive libraries. Permit me to spell out my solution in more detail: 1. Add a field in your thread context block (tcb) for errno. (The tcb already has space for all the hardware registers.) 2. When you switch from thread A to thread B. a. Save the registers in thread A's tcb. b. Save errno in thread A's tcb. c. Restore errno from thread B's tcb. d. Restore the registers from thread B's tcb. >|> If you have kernel threads, your kernel should arrange to map errno >|> separately for each thread. > >This is daft too. This means address space manipulations switching between >threads. On some architectures this can be very expensive. So much for threads >being light weight. Kernel thread system designers have, of course, recognized that context switching of kernel threads, while cheaper than process context switching, may still be somewhat expensive. So many systems with kernel threads (Solaris and UNICOS come to mind) actually implement a hybrid approach, scheduling a large number of user-level threads across a smaller number of kernel threads. Thank you for your kind remarks. -Andrew Hastings Encina Development Transarc