This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Recognizing the main thread based on its thread descriptor


On Wednesday 10 May 2017 02:58 PM, Florian Weimer wrote:
> Is there an internal way to tell if the current thread is the main thread?
> 
> I need this to allocate thread-local state in a particular way (the main
> thread needs to get a copy of the global variable for backwards
> compatibility).  Currently, this is handled with an initializer for the
> TLS variable and an override during pthread_create.  I want to switch
> this to dynamic initialization.
> 
> I can probably come up with a clever hack to express this, but I would
> prefer something explicit.

pthread_getattr_np uses the fact that stackblock is not set for a main
thread as the indication that it is the main thread.

Siddhesh


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]