I realized that pthread_once runs only once per execution instead of once per thread as I need. After reading libmicrohttpd and pthread docs, it seems that it is not possible to add any other thread initialization function besides the one in specified pthread_create. I could only find pthread_get/setspecific (and NULL value checking) as a solution for thread-local variable initialization. Please, let me know if I am going into the right direction.
Regards, Carlos Eduardo On Tue, Aug 12, 2014 at 6:20 PM, Christian Grothoff <[email protected]> wrote: > The real answer is that _you_ must measure it --- especially since the > real answer will depend on your platform, application and performance > requirements. I _suspect_ that it won't matter either way. > > Happy hacking! > > -Christian > > On 08/12/2014 10:36 PM, Carlos Eduardo Moreira dos Santos wrote: > > __thread keyword is simple to use, but I have to open one socket per > > thread, so I used pthread_once and also pthread_key_create to close it. > The > > only disadvantage I noticed is running pthread_once in every access > handler > > callback call. I don't know the details, but pthread_once should be fast > > enough to discard my code, isn't it? > > > > Best, > > Carlos Eduardo > > > > > > On Thu, Jul 3, 2014 at 5:05 AM, Christian Grothoff <[email protected]> > > wrote: > > > >> Well, pthread_key_create() also works, I guess, but I was thinking about > >> a slightly more lightweight method: > >> > >> http://gcc.gnu.org/onlinedocs/gcc-3.3/gcc/Thread-Local.html > >> > >> But both should work, and the best choice may really depend on your > >> application and its intended environment. > >
