🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.os2.programmer.misc
Article #253

Re: Thread-specific variables?

#253
From: Han Koster- IT
Date: Fri, 01 Oct 1993 08:19
32 lines
2256 bytes
Keith R. Bennett (kbennett@access.digex.net) wrote:
: 
: 
: 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?
: 

Yes, there is an errno for each thread. At least when you use
_begin_thread. I am not sure whether a new errno is created when you
directly call DosCreateThread.

With _begin_thread you can pass a parameter list to the thread. This
parameter list (it may contain simple variables as well as arrays and
structures) could be used to have thread-specifics.
This way you can preload some or all of these variables, which you
cannot when the thread allocated memory from the heap for its specifics.

WARNING: Do not use local variables (allocated on the stack) of the
procedure that calls _begin_thread as parameters to the thread. When
leaving the procedure, all your locals will be gone and the thread will
be 'ghost-operating' on your stack.

Han
Technical Details
Message-ID: <1993Oct1.081920.17311@cnplss5.cnps.philips.nl>
Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!udel!gatech!swrinde!cs.utexas.edu!uunet!mcsun!sun4nl!relay.philips.nl!cnplss5.cnps.philips.nl!han
References: <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-01 02:28:17 PST
Newsgroups: comp.os.os2.programmer.misc,bit.listserv.os2-l
Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!udel!gatech!swrinde!cs.utexas.edu!uunet!mcsun!sun4nl!relay.philips.nl!cnplss5.cnps.philips.nl!han
From: han@nlcd00.cft.philips.nl (Han Koster- IT)
Subject: Re: Thread-specific variables?
Message-ID: <1993Oct1.081920.17311@cnplss5.cnps.philips.nl>
Sender: news@cnplss5.cnps.philips.nl (USENET News System)
Organization: Philips Communications & Processing Services, Eindhoven
X-Newsreader: TIN [version 1.1 PL6]
References: <28efue$478@access.digex.net>
Date: Fri, 1 Oct 1993 08:19:20 GMT
Lines: 32