This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: std::call_once without TLS
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Chris Fairles <chris dot fairles at gmail dot com>
- Cc: Paolo Carlini <paolo dot carlini at oracle dot com>, "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Sun, 3 May 2009 11:55:10 +0100
- Subject: Re: std::call_once without TLS
- References: <4348dea50904021638j4973b798v856bc8715cfa8068@mail.gmail.com> <4348dea50904251357v68476479t4a14260a1c7d283c@mail.gmail.com> <49F428B9.8070401@oracle.com> <4348dea50904260608w660f521bgbe579c0315a7181d@mail.gmail.com> <49F468D9.6070102@oracle.com> <4348dea50904260725pa6cda22t34d2f296627e1894@mail.gmail.com> <49F47352.8050700@oracle.com> <4348dea50904260812p2d70a1a4n969c657b7d6e9a5b@mail.gmail.com> <4348dea50904291147u6764ca2dlce1177ee0c7a04d8@mail.gmail.com> <fac6bb500904291817i146ba446p314a4b98bd57786@mail.gmail.com>
2009/4/30 Chris Fairles:
>> Here's an ABI-compatible patch to fix libstdc++/39909, it would be
>> good if Chris or Benjamin could review it.
>>
>> Code using the new ABI will use a lock object on the caller's stack
>> and provide a pointer to it, if the pointer is NULL then the caller is
>> using the old ABI the global lock object.
>
> Many apologize for being absent on this issue.
>
> This non-ABI breaking patch applies only to 4.4 right?
I don't know. Paolo?
Preserving the ABI will be needed if users want to link objects
compiled using call_once from 4.4.0 and 4.5.0 -- but IMHO trying to
preserve ABI for the experimental C++0x stuff is too difficult and if
someone uses those features they should be prepared to accept that
they can't expect compatibility between major releases.
> Note that archs that want to use the new libstdc++ thread stuff are
> required to implement:
>
> int __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *))
> int __gthread_key_delete (__gthread_key_t key)
> void *__gthread_getspecific (__gthread_key_t key)
> int __gthread_setspecific (__gthread_key_t key, const void *ptr)
>
> (see gcc/gthr.h)
>
> Jonathon, if you have a better solution in mind, they are at your disposal.
I'm working on other things that I care about more (<future>,
std::bind, std::result_of ...) so I don't intend to revisit the
non-TLS std::call_once implementation. My only concern was preventing
valid code from calling std::terminate because of implementation
details in libstdc++, I don't care if it runs slowly on non-TLS
platforms, because I don't use any non-TLS platforms.
> As for trunk, can we still use the abi-breaking fix? I can't recall if
> function's move-assign operator is allowed to throw and even if its
> not, its certainly preferable to hold a global mutex in a
> stack-allocated unique_lock.
The main problem isn't that exceptions might leave the mutex locked
(they could probably be handled with try-catch blocks) but that
concurrent access to a single lock instance are undefined.
My last patch is not very different to the ABI-breaking one, but
manages to support the old ABI and fix it for the new, but if the
decision is made to break the std::call_once ABI for 4.5.0 I'm OK with
that.
Jonathan
Jonathan