Article View: comp.os.os2.programmer.misc
Article #251Re: Thread-specific variables?
From: Richard L. Krehbiel
Date: Mon, 04 Oct 1993 16:23
Date: Mon, 04 Oct 1993 16:23
34 lines
2221 bytes
2221 bytes
In article <28efue$478@access.digex.net> kbennett@access.digex.net (Keith R. Bennett) writes:
> I have a question about thread programming. Is there any way to make
> a given variable specific to an instance of a thread?
>
> The best I can think of so far is to use either local variables, or
> variables allocated from the heap. There is a large number of
> these variables that will be thread-specific, so I was thinking
> of putting them in structures and creating a new instance of each
> structure for each thread.
>
> The C++ programmers guide mentions that there is a separate copy of
> errno for each thread. Can I do that with my own variables?
There is a feature supplied by C Set/2 library called _threadstore.
It gives the address of a (void *) which is private to each thread.
You can put a pointer to thread-local information into this pointer:
void mythread(void *threadparam)
{
struct thread_info info; /* Allocate thread-private info on
this thread's stack */
*_threadstore = &info; /* Place that private info's
address into _threadstore */
[...]
elsewhere(void)
{
struct thread_info *info = *_threadstore;
--
Richard Krehbiel rich@kastle.com or richk@grebyn.com
OS/2 will do for me until AmigaDOS for the 386 comes along...
Technical Details
Message-ID:
<RICH.93Oct4162316@friend.kastle.com>Path:
arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!pipex!uunet!friend!richReferences:
<28efue$478@access.digex.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cd94,b690185ddc355787 X-Google-Attributes: gid10cd94,public X-Google-Thread: 11307a,b690185ddc355787 X-Google-Attributes: gid11307a,public X-Google-ArrivalTime: 1993-10-05 07:13:53 PST Newsgroups: comp.os.os2.programmer.misc,bit.listserv.os2-l Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!pipex!uunet!friend!rich From: rich@kastle.com (Richard L. Krehbiel) Subject: Re: Thread-specific variables? In-Reply-To: kbennett@access.digex.net's message of 30 Sep 1993 07:29:18 -0400 Message-ID: <RICH.93Oct4162316@friend.kastle.com> Lines: 31 Sender: rich@friend@kastle.com (Richard L. Krehbiel) Organization: Kastle Development Associates, Arlington, VA, USA References: <28efue$478@access.digex.net> Date: Mon, 4 Oct 1993 16:23:16 GMT