[comp.os.os2] Per thread global data

hjb@otter.hpl.hp.com (Harry Barman) (12/14/89)

Hi,

I'm looking for a means of keeping a piece of data associated with a thread.

I'm using large model Microsoft C,  and it seems that global data is 
available to all threads in the process,  and each thread has it's own stack.
What I want to do is to have some data that is global to the *thread* that can
be accessed by any procedure executed in the thread.

Anyone know any (cheap) ways to do this??

My last resort is to allocate a memory area for each thread,  and have a little
table that keeps track of which area corresponds to which thread.  The trouble
with this is that doing the table look up is kinda expensive,  I'd much prefer
to somehow add the memory area pointer to the thread's context.

Cheers,

Harry

hjb@otter.hpl.hp.com (Harry Barman) (12/20/89)

I had some people from microsoft contact me about this (thanks Chris and
Alistair)....

It looks like the best way to do per thread global data is to allocate a
stack segment for each thread,  and leave the global data at the bottom
of the area.  [the stack grows down from the top,  the global data is
accessed from SS:0]

There are a couple of places which could use this trick, like the multi-thread
C library (currently restricted to 32 threads!).  What concerns me is that
we don't all trip over each other,  I'd really like to see in the future is
some general way for threads to allocate thread-global data.

Thanks for the help,

Cheers,

Harry