Re: [PATCH 01/10] thread-utils: macros to unconditionally compile pthreads API
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Oct 27, 2018, 07:40 UTC
- Message-ID
- <CACsJy8AA8ABmV5myBEETWP0uSNNFjvUP5mE705OV9=JtyHgTkg@mail.gmail.com>
- In-Reply-To
- <20181027073125.GB26685@sigill.intra.peff.net>
On Sat, Oct 27, 2018 at 9:31 AM Jeff King <peff@peff.net> wrote:
Show 13 quoted lines
> > +#define pthread_setspecific(key, data)
> > +#define pthread_getspecific(key) NULL
>
> We expect to be able to store a void pointer here and get it back, which
> should work even for a single thread. Do we need something like:
>
> extern void *pthread_specific_data;
>
> #define pthread_setspecific(key, data) do { \
> pthread_specific_data = data; \
> } while(0)
>
> void pthread_getspecific(key) pthread_specific_dataThe data is per key though so a correct implementation may involve a hashmap or a list. It does simplify index-pack which has to fall back to nothread_data when pthreads is not available. But with index-pack being the only call site that can take advantage of this (run-command.c probably will use real pthreads library anyway), I'm not sure if it's worth really implementing these functions.
-- Duy