Thread (59 messages) 59 messages, 3 authors, 2018-11-03

Re: [PATCH 01/10] thread-utils: macros to unconditionally compile pthreads API

From: Duy Nguyen <hidden>
Date: 2018-10-27 14:44:11

On Sat, Oct 27, 2018 at 10:15 AM Jeff King [off-list ref] wrote:
On Sat, Oct 27, 2018 at 09:40:13AM +0200, Duy Nguyen wrote:
quoted
quoted
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_data
The data is per key though so a correct implementation may involve a
hashmap or a list.
Ah, yeah, you're right, I was mixing up the thread id and the key in my
head. I think it would just be an array of void pointers, with
pthread_key_create() returning an static index.
We could redefine pthread_key_t as "void *" though, then
_setspecific(key, data) is key = data; But there will be more changes
in index-pack.c to take advantage of it. I took a stab but couldn't
figure out fast enough where _setspecific(.., &nothread_data) should
be called in NO_PTHREADS mode (to simplify get_thread_data() to just a
wrapper of _getspecific) and got bored. It could be a micro project
for someone really wants to learn about index-pack.c
-- 
Duy
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help