This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Fwd: local equivalent for pthread_once() in glibc?
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: Florian Weimer <fweimer at redhat dot com>, libc-alpha at sourceware dot org
- Date: Mon, 26 Jun 2017 10:12:33 -0300
- Subject: Re: Fwd: local equivalent for pthread_once() in glibc?
- Authentication-results: sourceware.org; auth=none
- References: <9EBFE06E-AF1D-48E9-85AB-B74C048438B1@oracle.com> <F050C948-50BF-4305-84AC-9003F97D9F59@oracle.com> <be02ff5c-0313-29b2-e807-1a618559ec9c@redhat.com> <ff82b3b2-e282-9d88-775f-9fb46296787f@linaro.org> <d8588f17-b5b6-181d-2e97-7de012e89244@redhat.com> <6e7c1667-bc63-e999-9b53-b0ca221c90a8@linaro.org> <f9d991c7-ae6e-5fec-d773-512d1239059b@redhat.com> <7145698d-7154-af1a-86d5-0f1764855b9e@linaro.org> <c27acd4c-40fb-a97b-439b-b45c7c1e3a80@redhat.com>
On 26/06/2017 09:51, Florian Weimer wrote:
> On 06/26/2017 02:13 PM, Adhemerval Zanella wrote:
>>
>>
>> On 25/06/2017 12:46, Florian Weimer wrote:
>>> On 05/17/2017 04:51 PM, Adhemerval Zanella wrote:
>>>> Right, but this is not seem the case for tunable where malloc_consolidate is
>>>> called from ptmalloc_init (at least for main_arena). In any case, I still
>>>> think that for adequate __malloc_initialized access using C11 atomic since
>>>> its access is still done concurrently (that why I asked if using __libc_once
>>>> would be simpler).
>>>
>>> I don't understand. The concurrent access solely consists of reads. We
>>> do not use atomics in that case.
>>
>> My understanding and my point is even for these cases we should aim for
>> C11 atomic accesses, even for relaxed loads which on most architectures
>> will map to normal loads.
>
> I don't think this is true. If the last write happen before all the
> concurrent read accesses, we don't need atomics. To me, this is quite
> clear because this is what happens with locks, where we usually don't
> use atomics within the critical section, either.
I do agree with your rationale, but from Torvald comment on BZ #20822 [1]
fix my understanding is to still use atomic relaxed MO for such cases
simply for consistency (and I will add to add more readability to state
the variable is indeed read concurrently and relaxed MO is suffice).
[1] https://sourceware.org/ml/libc-alpha/2016-12/msg00820.html