[163] in Pthreads mailing list archive
Re: An idea for pthreads
daemon@ATHENA.MIT.EDU (Antony Courtney)
Wed Oct 25 19:52:15 1995
To: pthreads@MIT.EDU
In-Reply-To: Your message of "Wed, 25 Oct 1995 17:25:59 EDT."
<9510252125.AA05720@cujo.cygnus.com>
From: Antony Courtney <antony@apocalypse.org>
Date: Wed, 25 Oct 1995 16:37:58 +0200
In message <9510252125.AA05720@cujo.cygnus.com>you write:
>
> From: aab@cichlid.com (Andy Burgess)
> Date: Wed, 25 Oct 95 12:24 PDT
>
> I think the idea was to call the C lib fcn and then do some housekeeping
> before returning, eg (in pseudo code): errno_table[thread] = errno
>
>You'd have to disable the thread scheduler in order to ensure that
>errno wasn't changed by some other thread between the setting and
>reading.
Right. The swap would (and should!) be done by the thread scheduler itself.
Instead of thinking of errno as "just another variable", think of it as
akin to a register, which the scheduler shares between all threads. So:
- there is just one true location for errno, used by all threads
- there is no funky macrology for getting at a "per-thread errno";
you just refer to the symbol "errno", so libraries which use this
symbol continue to work.
- every time the thread scheduler does a thread switch, it stores
the current value of errno along with the thread's register set in
a per-thread data structure, and swaps in the value of errno
which belongs to the thread which is about to run. Quite cheap,
all told.
>Not pretty. Better to avoid the situation completely if
>possible.
It seems to me much "prettier" than trying to maintain assembly language for
N different platforms.
Also,
-antony