This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Recognizing the main thread based on its thread descriptor
- From: Florian Weimer <fweimer at redhat dot com>
- To: GNU C Library <libc-alpha at sourceware dot org>
- Date: Wed, 10 May 2017 11:28:04 +0200
- Subject: Recognizing the main thread based on its thread descriptor
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=fweimer at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9383580C0C
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9383580C0C
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.
Thanks,
Florian