Windows supports local thread storage (TLS) in the DLL. This can be very practical if you want to have memory blocks for a stream with a unique value (unique to each stream). Inside any other function from a DLL, you can easily get the value corresponding to the current thread . This is very useful in some scenarios. Check here for more details.
I do not use pthreads myself, but I believe that a slot for storing in the stream is introduced to make working with TLS more comfortable.
UPDATED . From your comment, I see that you misunderstood my answer. I am not a POSIX developer, I only develop in Win32, and your question is about the capabilities of the WIn32 API for distributing threads and freeing them. Iām trying to explain the possibilities, and you can decide for yourself which one is best for your specific scenarios.
In Win32, the pthread_XXX functions are equivalent:
I did not recommend you use the __ declspec (thread) construct, which is more specific to the compiler.
An example of using local thread storage shows how to use a local storage stream (TLS) without DLLs, but I personally like and use TLS only in DLLs.
The destructor parameter of the pthread_key_create function has no analogue in Win32, but I do not see any problem here. All C / C ++ compilers support the __try {/**/} __finally {/**/} Structured Exception Handling construct, so you can use it in the body of your stream function and implement the Purge resources path, since you can do this in main stream.
I'm sorry that you did not include an example in your question that shows how you usually use the pthread_key_create destructor . I find that examples can clarify a lot without a lot of words. Therefore, if my answer does not help you, we can better explain everything in the examples: you write an example and probably a short comment about what it should do, and I could write the same code using the Win32 API only in C or C + +.
source share