{"thread":{"id":"51144","subject":"[PATCH 0/1] trace2: fix tracing when NO_PTHREADS is defined","startedAt":"2019-05-21T19:34:01Z","lastAt":"2019-05-28T17:14:11Z","messageCount":10,"participants":["Jeff Hostetler via GitGitGadget","Jeff King","Jeff Hostetler","Duy Nguyen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"376009","messageId":"pull.222.git.gitgitgadget@gmail.com","threadId":"51144","inReplyTo":null,"subject":"[PATCH 0/1] trace2: fix tracing when NO_PTHREADS is defined","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-05-21T19:33:58Z","receivedAt":"2019-05-21T19:34:01Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"This commit addresses the problem reported in:\nhttps://public-inbox.org/git/92cfdf43-8841-9c5a-7838-dda995038908@jeffhostetler.com/T/#mbaf8069f6d1bc18d5a02d3682a1f9282f5547ea9\n\nAs Duy suggested, pthread_getspecific() just returns NULL when NO_PTHREADS\nis defined. And pthread_setspecific() silently does not nothing. So this\nproblem was hidden from view.\n\nI have to wonder if we should update pthread_*specific() to call BUG() when\nNO_PTHREADS is defined as a way to catch unguarded usages easier or make\nthis issue more clear.\n\nJeff Hostetler (1):\n  trace2: fix tracing when NO_PTHREADS is defined\n\n trace2/tr2_tls.c | 12 +++++++++---\n 1 file changed, 9 insertions(+), 3 deletions(-)\n\n\nbase-commit: aa25c82427ae70aebf3b8f970f2afd54e9a2a8c6\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-222%2Fjeffhostetler%2Ftrace2-no-pthread-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-222/jeffhostetler/trace2-no-pthread-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/222\n-- \ngitgitgadget\n"},{"id":"376010","messageId":"c195394c86c1ee599945cd4ea65633a72a3fd30e.1558467237.git.gitgitgadget@gmail.com","threadId":"51144","inReplyTo":"pull.222.git.gitgitgadget@gmail.com","subject":"[PATCH 1/1] trace2: fix tracing when NO_PTHREADS is defined","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-05-21T19:33:59Z","receivedAt":"2019-05-21T19:34:03Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nTeach trace2 TLS code to not rely on pthread_getspecific() when NO_PTHREADS\nis defined.  Instead, always assume the context data of the main thread.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n trace2/tr2_tls.c | 12 +++++++++---\n 1 file changed, 9 insertions(+), 3 deletions(-)\n\ndiff --git a/trace2/tr2_tls.c b/trace2/tr2_tls.c\nindex e76d8c5d92..067c23755f 100644\n--- a/trace2/tr2_tls.c\n+++ b/trace2/tr2_tls.c\n@@ -61,7 +61,12 @@ struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name,\n \n struct tr2tls_thread_ctx *tr2tls_get_self(void)\n {\n-\tstruct tr2tls_thread_ctx *ctx = pthread_getspecific(tr2tls_key);\n+\tstruct tr2tls_thread_ctx *ctx;\n+\n+\tif (!HAVE_THREADS)\n+\t\treturn tr2tls_thread_main;\n+\n+\tctx = pthread_getspecific(tr2tls_key);\n \n \t/*\n \t * If the thread-proc did not call trace2_thread_start(), we won't\n@@ -76,9 +81,10 @@ struct tr2tls_thread_ctx *tr2tls_get_self(void)\n \n int tr2tls_is_main_thread(void)\n {\n-\tstruct tr2tls_thread_ctx *ctx = pthread_getspecific(tr2tls_key);\n+\tif (!HAVE_THREADS)\n+\t\treturn 1;\n \n-\treturn ctx == tr2tls_thread_main;\n+\treturn pthread_getspecific(tr2tls_key) == tr2tls_thread_main;\n }\n \n void tr2tls_unset_self(void)\n-- \ngitgitgadget\n"},{"id":"376018","messageId":"20190521212744.GC14807@sigill.intra.peff.net","threadId":"51144","inReplyTo":"pull.222.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 0/1] trace2: fix tracing when NO_PTHREADS is defined","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-05-21T21:27:44Z","receivedAt":"2019-05-21T21:27:47Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, May 21, 2019 at 12:33:58PM -0700, Jeff Hostetler via GitGitGadget wrote:\n\n> As Duy suggested, pthread_getspecific() just returns NULL when NO_PTHREADS\n> is defined. And pthread_setspecific() silently does not nothing. So this\n> problem was hidden from view.\n> \n> I have to wonder if we should update pthread_*specific() to call BUG() when\n> NO_PTHREADS is defined as a way to catch unguarded usages easier or make\n> this issue more clear.\n\nI think it should actually store the data asked for by the caller, as if\nwe were the single thread running. We discussed this as the time of\nrefactoring NO_PTHREADS, but there was only one caller that would have\nbenefited. Now there are two. ;)\n\nDiscussion in the subthread of this patch:\n\n  https://public-inbox.org/git/20181027071003.1347-2-pclouds@gmail.com/\n\n-Peff\n"},{"id":"376059","messageId":"97796007-db6e-f2ea-91ae-3113b74e4ae9@jeffhostetler.com","threadId":"51144","inReplyTo":"20190521212744.GC14807@sigill.intra.peff.net","subject":"Re: [PATCH 0/1] trace2: fix tracing when NO_PTHREADS is defined","fromName":"Jeff Hostetler","fromEmail":"git@jeffhostetler.com","sentAt":"2019-05-22T13:23:39Z","receivedAt":"2019-05-22T13:23:42Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"\n\nOn 5/21/2019 5:27 PM, Jeff King wrote:\n> On Tue, May 21, 2019 at 12:33:58PM -0700, Jeff Hostetler via GitGitGadget wrote:\n> \n>> As Duy suggested, pthread_getspecific() just returns NULL when NO_PTHREADS\n>> is defined. And pthread_setspecific() silently does not nothing. So this\n>> problem was hidden from view.\n>>\n>> I have to wonder if we should update pthread_*specific() to call BUG() when\n>> NO_PTHREADS is defined as a way to catch unguarded usages easier or make\n>> this issue more clear.\n> \n> I think it should actually store the data asked for by the caller, as if\n> we were the single thread running. We discussed this as the time of\n> refactoring NO_PTHREADS, but there was only one caller that would have\n> benefited. Now there are two. ;)\n> \n> Discussion in the subthread of this patch:\n> \n>    https://public-inbox.org/git/20181027071003.1347-2-pclouds@gmail.com/\n> \n> -Peff\n> \n\nI was wondering about that too as the proper long term solution.\nWe would need (as the discussion suggests [1]) to properly\nrespect/represent the pthread_key_t argument.\n\nFor now, I've guarded my usage of pthread_getspecific() in the trace2\n(similar to what index-pack does), so its not urgent that we update it.\nAnd I'd rather we take this simple trace2 fix now and not try to combine\nit with fixes for the pthread macros.  Especially now as we're in the RC\ncycle for 2.22.\n\nI'll make a note to revisit the pthread code after 2.22.\n\nThanks\nJeff\n\n\n[1] \nhttps://public-inbox.org/git/CACsJy8DLW_smOJd6aCoRcJZxQ2Lzut5US=sPadj7=fhne0UHGg@mail.gmail.com/\n\n"},{"id":"376093","messageId":"20190523055108.GA20871@sigill.intra.peff.net","threadId":"51144","inReplyTo":"97796007-db6e-f2ea-91ae-3113b74e4ae9@jeffhostetler.com","subject":"Re: [PATCH 0/1] trace2: fix tracing when NO_PTHREADS is defined","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-05-23T05:51:09Z","receivedAt":"2019-05-23T05:51:14Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, May 22, 2019 at 09:23:39AM -0400, Jeff Hostetler wrote:\n\n> I was wondering about that too as the proper long term solution.\n> We would need (as the discussion suggests [1]) to properly\n> respect/represent the pthread_key_t argument.\n> \n> For now, I've guarded my usage of pthread_getspecific() in the trace2\n> (similar to what index-pack does), so its not urgent that we update it.\n> And I'd rather we take this simple trace2 fix now and not try to combine\n> it with fixes for the pthread macros.  Especially now as we're in the RC\n> cycle for 2.22.\n\nYeah, I think that makes sense.\n\n> I'll make a note to revisit the pthread code after 2.22.\n\nFor fun, here's a constant-time zero-allocation implementation that I\ncame up with. It passes t0211 with NO_PTHREADS, but I didn't test it\nbeyond that.\n\ndiff --git a/thread-utils.h b/thread-utils.h\nindex 4961487ed9..f466215742 100644\n--- a/thread-utils.h\n+++ b/thread-utils.h\n@@ -18,7 +18,7 @@\n #define pthread_t int\n #define pthread_mutex_t int\n #define pthread_cond_t int\n-#define pthread_key_t int\n+#define pthread_key_t git_pthread_key_t\n \n #define pthread_mutex_init(mutex, attr) dummy_pthread_init(mutex)\n #define pthread_mutex_lock(mutex)\n@@ -31,16 +31,49 @@\n #define pthread_cond_broadcast(cond)\n #define pthread_cond_destroy(cond)\n \n-#define pthread_key_create(key, attr) dummy_pthread_init(key)\n-#define pthread_key_delete(key)\n+#define pthread_key_create(key, destroy) git_pthread_key_create(key, destroy)\n+#define pthread_key_delete(key) git_pthread_key_delete(key)\n \n #define pthread_create(thread, attr, fn, data) \\\n \tdummy_pthread_create(thread, attr, fn, data)\n #define pthread_join(thread, retval) \\\n \tdummy_pthread_join(thread, retval)\n \n-#define pthread_setspecific(key, data)\n-#define pthread_getspecific(key) NULL\n+#define pthread_setspecific(key, data) git_pthread_setspecific(key, data)\n+#define pthread_getspecific(key) git_pthread_getspecific(key)\n+\n+typedef struct {\n+\tvoid *data;\n+\t/* extra indirection because setspecific is passed key by value */\n+\tvoid **vdata;\n+} git_pthread_key_t;\n+\n+static inline int git_pthread_key_create(git_pthread_key_t *key,\n+\t\t\t\t\t void (*destroy)(void *))\n+{\n+\tkey->data = NULL;\n+\tkey->vdata = &key->data;\n+\t/* We don't use this; alternatively we could all via atexit(). */\n+\tif (destroy)\n+\t\tBUG(\"NO_PTHREADS does not support pthread key destructors\");\n+\treturn 0;\n+}\n+\n+static inline int git_pthread_key_delete(git_pthread_key_t key)\n+{\n+\t/* noop */\n+\treturn 0;\n+}\n+\n+static inline void git_pthread_setspecific(git_pthread_key_t key, void *data)\n+{\n+\t*(key.vdata) = data;\n+}\n+\n+static inline void *git_pthread_getspecific(git_pthread_key_t key)\n+{\n+\treturn key.data;\n+}\n \n int dummy_pthread_create(pthread_t *pthread, const void *attr,\n \t\t\t void *(*fn)(void *), void *data);\n"},{"id":"376105","messageId":"50badedb-7856-374e-b14c-1eb1951c63f0@jeffhostetler.com","threadId":"51144","inReplyTo":"20190523055108.GA20871@sigill.intra.peff.net","subject":"Re: [PATCH 0/1] trace2: fix tracing when NO_PTHREADS is defined","fromName":"Jeff Hostetler","fromEmail":"git@jeffhostetler.com","sentAt":"2019-05-23T13:55:12Z","receivedAt":"2019-05-23T13:55:16Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"\n\nOn 5/23/2019 1:51 AM, Jeff King wrote:\n> On Wed, May 22, 2019 at 09:23:39AM -0400, Jeff Hostetler wrote:\n> \n>> I was wondering about that too as the proper long term solution.\n>> We would need (as the discussion suggests [1]) to properly\n>> respect/represent the pthread_key_t argument.\n>>\n>> For now, I've guarded my usage of pthread_getspecific() in the trace2\n>> (similar to what index-pack does), so its not urgent that we update it.\n>> And I'd rather we take this simple trace2 fix now and not try to combine\n>> it with fixes for the pthread macros.  Especially now as we're in the RC\n>> cycle for 2.22.\n> \n> Yeah, I think that makes sense.\n> \n>> I'll make a note to revisit the pthread code after 2.22.\n> \n> For fun, here's a constant-time zero-allocation implementation that I\n> came up with. It passes t0211 with NO_PTHREADS, but I didn't test it\n> beyond that.\n> \n> diff --git a/thread-utils.h b/thread-utils.h\n> index 4961487ed9..f466215742 100644\n> --- a/thread-utils.h\n> +++ b/thread-utils.h\n> @@ -18,7 +18,7 @@\n>   #define pthread_t int\n>   #define pthread_mutex_t int\n>   #define pthread_cond_t int\n> -#define pthread_key_t int\n> +#define pthread_key_t git_pthread_key_t\n>   \n>   #define pthread_mutex_init(mutex, attr) dummy_pthread_init(mutex)\n>   #define pthread_mutex_lock(mutex)\n> @@ -31,16 +31,49 @@\n>   #define pthread_cond_broadcast(cond)\n>   #define pthread_cond_destroy(cond)\n>   \n> -#define pthread_key_create(key, attr) dummy_pthread_init(key)\n> -#define pthread_key_delete(key)\n> +#define pthread_key_create(key, destroy) git_pthread_key_create(key, destroy)\n> +#define pthread_key_delete(key) git_pthread_key_delete(key)\n>   \n>   #define pthread_create(thread, attr, fn, data) \\\n>   \tdummy_pthread_create(thread, attr, fn, data)\n>   #define pthread_join(thread, retval) \\\n>   \tdummy_pthread_join(thread, retval)\n>   \n> -#define pthread_setspecific(key, data)\n> -#define pthread_getspecific(key) NULL\n> +#define pthread_setspecific(key, data) git_pthread_setspecific(key, data)\n> +#define pthread_getspecific(key) git_pthread_getspecific(key)\n> +\n> +typedef struct {\n> +\tvoid *data;\n> +\t/* extra indirection because setspecific is passed key by value */\n> +\tvoid **vdata;\n> +} git_pthread_key_t;\n> +\n> +static inline int git_pthread_key_create(git_pthread_key_t *key,\n> +\t\t\t\t\t void (*destroy)(void *))\n> +{\n> +\tkey->data = NULL;\n> +\tkey->vdata = &key->data;\n> +\t/* We don't use this; alternatively we could all via atexit(). */\n> +\tif (destroy)\n> +\t\tBUG(\"NO_PTHREADS does not support pthread key destructors\");\n> +\treturn 0;\n> +}\n> +\n> +static inline int git_pthread_key_delete(git_pthread_key_t key)\n> +{\n> +\t/* noop */\n> +\treturn 0;\n> +}\n> +\n> +static inline void git_pthread_setspecific(git_pthread_key_t key, void *data)\n> +{\n> +\t*(key.vdata) = data;\n> +}\n> +\n> +static inline void *git_pthread_getspecific(git_pthread_key_t key)\n> +{\n> +\treturn key.data;\n> +}\n>   \n>   int dummy_pthread_create(pthread_t *pthread, const void *attr,\n>   \t\t\t void *(*fn)(void *), void *data);\n> \n\nThanks!  I'll play with this and submit something after 2.22 and\nthings slow down a bit.\n\nJeff\n\n"},{"id":"376214","messageId":"CACsJy8D7w4sC_tchx-Q80PCiu+2hYfkZo22_Vb3vgJ+xvgUAAA@mail.gmail.com","threadId":"51144","inReplyTo":"20190523055108.GA20871@sigill.intra.peff.net","subject":"Re: [PATCH 0/1] trace2: fix tracing when NO_PTHREADS is defined","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2019-05-25T10:43:55Z","receivedAt":"2019-05-25T10:44:24Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, May 23, 2019 at 12:51 PM Jeff King <peff@peff.net> wrote:\n> For fun, here's a constant-time zero-allocation implementation that I\n> came up with. It passes t0211 with NO_PTHREADS, but I didn't test it\n> beyond that.\n>\n> diff --git a/thread-utils.h b/thread-utils.h\n> index 4961487ed9..f466215742 100644\n> --- a/thread-utils.h\n> +++ b/thread-utils.h\n> @@ -18,7 +18,7 @@\n>  #define pthread_t int\n>  #define pthread_mutex_t int\n>  #define pthread_cond_t int\n> -#define pthread_key_t int\n> +#define pthread_key_t git_pthread_key_t\n>\n>  #define pthread_mutex_init(mutex, attr) dummy_pthread_init(mutex)\n>  #define pthread_mutex_lock(mutex)\n> @@ -31,16 +31,49 @@\n>  #define pthread_cond_broadcast(cond)\n>  #define pthread_cond_destroy(cond)\n>\n> -#define pthread_key_create(key, attr) dummy_pthread_init(key)\n> -#define pthread_key_delete(key)\n> +#define pthread_key_create(key, destroy) git_pthread_key_create(key, destroy)\n> +#define pthread_key_delete(key) git_pthread_key_delete(key)\n>\n>  #define pthread_create(thread, attr, fn, data) \\\n>         dummy_pthread_create(thread, attr, fn, data)\n>  #define pthread_join(thread, retval) \\\n>         dummy_pthread_join(thread, retval)\n>\n> -#define pthread_setspecific(key, data)\n> -#define pthread_getspecific(key) NULL\n> +#define pthread_setspecific(key, data) git_pthread_setspecific(key, data)\n> +#define pthread_getspecific(key) git_pthread_getspecific(key)\n> +\n> +typedef struct {\n> +       void *data;\n> +       /* extra indirection because setspecific is passed key by value */\n> +       void **vdata;\n\nHa! I was thinking a separate key->value mapping which is complicated\nin C. But this works pretty well for a single thread, and it even\nsupports multiple keys.\n\n> +} git_pthread_key_t;\n> +\n> +static inline int git_pthread_key_create(git_pthread_key_t *key,\n> +                                        void (*destroy)(void *))\n> +{\n> +       key->data = NULL;\n> +       key->vdata = &key->data;\n> +       /* We don't use this; alternatively we could all via atexit(). */\n> +       if (destroy)\n> +               BUG(\"NO_PTHREADS does not support pthread key destructors\");\n> +       return 0;\n> +}\n> +\n> +static inline int git_pthread_key_delete(git_pthread_key_t key)\n> +{\n> +       /* noop */\n> +       return 0;\n> +}\n> +\n> +static inline void git_pthread_setspecific(git_pthread_key_t key, void *data)\n> +{\n> +       *(key.vdata) = data;\n> +}\n> +\n> +static inline void *git_pthread_getspecific(git_pthread_key_t key)\n> +{\n> +       return key.data;\n> +}\n>\n>  int dummy_pthread_create(pthread_t *pthread, const void *attr,\n>                          void *(*fn)(void *), void *data);\n-- \nDuy\n"},{"id":"376273","messageId":"20190528062804.GE7946@sigill.intra.peff.net","threadId":"51144","inReplyTo":"CACsJy8D7w4sC_tchx-Q80PCiu+2hYfkZo22_Vb3vgJ+xvgUAAA@mail.gmail.com","subject":"Re: [PATCH 0/1] trace2: fix tracing when NO_PTHREADS is defined","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-05-28T06:28:05Z","receivedAt":"2019-05-28T06:28:09Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, May 25, 2019 at 05:43:55PM +0700, Duy Nguyen wrote:\n\n> > +typedef struct {\n> > +       void *data;\n> > +       /* extra indirection because setspecific is passed key by value */\n> > +       void **vdata;\n> \n> Ha! I was thinking a separate key->value mapping which is complicated\n> in C. But this works pretty well for a single thread, and it even\n> supports multiple keys.\n\nI really wish that all of the functions passed the pthread_key_t by\nreference. That would make it possible to define the key as a single\npointer.\n\nI'm not sure if pthread_key_t's are meant to be shallow-copyable. I.e.,\nshould this work:\n\n  void foo(pthread_key_t *out)\n  {\n\tpthread_key_t tmp;\n\tpthread_key_create(&tmp, NULL);\n\t*out = tmp;\n  }\n  ...\n  pthread_key_t k;\n  foo(&k);\n  pthread_setspecific(k, some_ptr);\n\nIt does not with my proposed plan, because the pointer in tmp.data went\nout of scope, leaving tmp.vdata (and thus k.vdata) as a dangling\npointer.\n\nThe code above seems like a vaguely crazy thing to do. But if we want to\nbe absolutely paranoid, we'd have to malloc() an extra pointer in the\ncreate() function, instead of carrying it inside the key. Or just make a\nglobal \"void *thread_specific_data[PTHREAD_KEYS_MAX]\" and make each key\nan integer index into it.\n\nIt's pretty clear that they expect one of those two implementations,\ngiven that POSIX says key creation can report either ENOMEM, or EAGAIN\nif we exceed PTHREAD_KEYS_MAX. :)\n\n-Peff\n"},{"id":"376308","messageId":"47db8f30-846b-12d0-250e-4bccf1e19c45@jeffhostetler.com","threadId":"51144","inReplyTo":"20190528062804.GE7946@sigill.intra.peff.net","subject":"Re: [PATCH 0/1] trace2: fix tracing when NO_PTHREADS is defined","fromName":"Jeff Hostetler","fromEmail":"git@jeffhostetler.com","sentAt":"2019-05-28T14:57:50Z","receivedAt":"2019-05-28T14:57:53Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"\n\nOn 5/28/2019 2:28 AM, Jeff King wrote:\n> On Sat, May 25, 2019 at 05:43:55PM +0700, Duy Nguyen wrote:\n> \n>>> +typedef struct {\n>>> +       void *data;\n>>> +       /* extra indirection because setspecific is passed key by value */\n>>> +       void **vdata;\n>>\n>> Ha! I was thinking a separate key->value mapping which is complicated\n>> in C. But this works pretty well for a single thread, and it even\n>> supports multiple keys.\n> \n> I really wish that all of the functions passed the pthread_key_t by\n> reference. That would make it possible to define the key as a single\n> pointer.\n> \n> I'm not sure if pthread_key_t's are meant to be shallow-copyable. I.e.,\n> should this work:\n> \n>    void foo(pthread_key_t *out)\n>    {\n> \tpthread_key_t tmp;\n> \tpthread_key_create(&tmp, NULL);\n> \t*out = tmp;\n>    }\n>    ...\n>    pthread_key_t k;\n>    foo(&k);\n>    pthread_setspecific(k, some_ptr);\n> \n> It does not with my proposed plan, because the pointer in tmp.data went\n> out of scope, leaving tmp.vdata (and thus k.vdata) as a dangling\n> pointer.\n> \n> The code above seems like a vaguely crazy thing to do. But if we want to\n> be absolutely paranoid, we'd have to malloc() an extra pointer in the\n> create() function, instead of carrying it inside the key. Or just make a\n> global \"void *thread_specific_data[PTHREAD_KEYS_MAX]\" and make each key\n> an integer index into it.\n> \n> It's pretty clear that they expect one of those two implementations,\n> given that POSIX says key creation can report either ENOMEM, or EAGAIN\n> if we exceed PTHREAD_KEYS_MAX. :)\n> \n> -Peff\n> \n\n\nYes, a fixed global void* array should be fine.\nBesides there aren't that many calls to pthread_key_create()  (My use in\nTrace2 is the second, right?), so just create an arbitrary value for\nPTHREAD_KEYS_MAX and be done.\n\n\nJeff\n"},{"id":"376324","messageId":"xmqqv9xu33j6.fsf@gitster-ct.c.googlers.com","threadId":"51144","inReplyTo":"97796007-db6e-f2ea-91ae-3113b74e4ae9@jeffhostetler.com","subject":"Re: [PATCH 0/1] trace2: fix tracing when NO_PTHREADS is defined","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-05-28T17:14:05Z","receivedAt":"2019-05-28T17:14:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff Hostetler <git@jeffhostetler.com> writes:\n\n> For now, I've guarded my usage of pthread_getspecific() in the trace2\n> (similar to what index-pack does), so its not urgent that we update it.\n> And I'd rather we take this simple trace2 fix now and not try to combine\n> it with fixes for the pthread macros.  Especially now as we're in the RC\n> cycle for 2.22.\n>\n> I'll make a note to revisit the pthread code after 2.22.\n\nThanks, both.  The above direction makes sense for me, too.\n\n"}]}