[PATCH] malloc: Ensure that ptmalloc_init runs only once
Florian Weimer
fweimer@redhat.com
Fri Jun 18 05:45:50 GMT 2021
* Siddhesh Poyarekar:
> On 6/17/21 8:01 PM, Florian Weimer via Libc-alpha wrote:
>> * Siddhesh Poyarekar via Libc-alpha:
>>
>>> It is possible that multiple threads simultaneously enter
>>> ptmalloc_init and succeed the < 0 check. Make the comparison and
>>> setting of __malloc_initialized atomic so that only one of them goes
>>> through. Additionally, if a thread sees that another thread is
>>> running the initialization (i.e. __malloc_initialized == 0) then wait
>>> till it is done.
>> No, this cannot happen because pthread_create calls malloc before
>> creating the new thread.
>
> Yes but I wonder if we should rely on that. If we decide to rely on
> this semantic then we implicitly specify thread creation through
> methods other than pthread_create that happen to not call malloc as
> unsupported.
There is no way to allocate a TCB for such foreign threads, and malloc
depends on the TCB, so this is not something that can work for
completely different reasons.
THanks,
Florian
More information about the Libc-alpha
mailing list