[PATCH 2/2] Initialize tunable list with the GLIBC_TUNABLES environment variable
Carlos O'Donell
carlos@redhat.com
Wed Jan 13 02:44:00 GMT 2016
On 01/11/2016 09:45 AM, Siddhesh Poyarekar wrote:
> On Mon, Jan 11, 2016 at 02:51:36PM +0100, Andreas Schwab wrote:
>> Siddhesh Poyarekar <sid@reserved-bit.com> writes:
>>
>>> void
>>> __tunables_init (char **envp)
>>> {
>>> - /* Empty for now. */
>>> + static bool initialized = false;
>>> +
>>> + if (__glibc_likely (initialized))
>>> + return;
>>
>> Is this supposed to be thread-safe?
>
> This is called only from the libc.so and libpthread.so constructors.
> So the first run will always happen exclusively in the main thread
> through either library constructor.
Not true if you link statically and dlopen, at which point you could
have multiple threads, and you call dlopen which loads
libc.so/libpthread.so's constructors?
You can write a simple static test case that creates N threads and
calls dlopen on some DSO to test this.
> Even in case the constructors do get called in parallel in different
> threads, they should get synchronized by the dynamic linker load lock,
> so you'd never have concurrent calls to __tunables_init that race on
> the value of initialized.
Please include a concurrency note there then, that this is protected
by the load lock?
Cheers,
Carlos.
More information about the Libc-alpha
mailing list