Branko Čibej wrote: > Mladen Turk wrote: >> Hi, >> >> pthreads have option to register destruct callback >> for private thread keys created. >> Here is the patch that allow that for WIN32 but >> only when compiled as dll. >> >> Any comments or objections? >> The consequence is that the DllMain is added, and >> I suppose its not possible to have that functionality >> with static apr lib. >> OTOH it allows to have the same behavior like with >> pthreads actually calling provided callback to >> the apr_threadkey_private_create instead just ignoring >> it. > > I've recently learned of a trick that would make this work anywhere, > even in a static lib, and wouldn't need DllMain. You can actually insert > your own constructors and destructors into the CRT's tables.
I had a similar issue with this proposal, and came to a different possible solution ... we could run the destructors as part of the thread return processing from our apr thread start function when the thread returns control. I also find the table code very ugly... allocating a pool datum to track these keys in a hash seems in the global pool seems to make so much more sense. Garrett pointed out that the code to accomplish this might not be thread safe, but I think that's an underlying bug in the pool datum code, not a showstopper.
