Thanks for all answers. I don't entirely understand most of them though as I'm 
not really familiar with the implications of TLS or how to use it correctly. 
Also, do we need per-thread or per-task data here?
You would expect getopt() to be used only on the many thread since that
is the only thread that receives argc and argv.
So if it is only used in one thread there would only be a copy of the data? 
What if I spawn multiple threads and call getopt only on one?

Yes there is only one copy of the data for each thread that uses getopt().  In the normal case, only one thread, the main thread, uses getopt().

I had considered a single allocation for the main thread.  If other threads in the same task call getopt(), it could share that single per-task allocation (rather than creating another copy), i.e., each thread's TLS data would refer to the same memory.  That is how other Unix systems work.


Reply via email to