Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How to cleanup TSD in Win32?

cleanup TSD Win32
0
Posted

How to cleanup TSD in Win32?

0

>I am forced to use TSD in multithreading existing code. I just ran >into the problem that, while the destructor function argument to >pthread_key_create() and thr_keycreate() appears ideal, there is no >such facility with the NT TlsAlloc() and that related stuff. It’s pretty easy to write the code to provide this facility. Basically you have to wrap TlsAlloc() and TlsFree() in some additional logic. This logic maintains a list of all the keys currently allocated for your process. For each allocated key it stores the address of the destructor routine for that key (supplied as an argument to the wrapped version of TlsAlloc()). When a thread exits it iterates through these records; for every key that references valid data (i.e. TlsGetValue() returns non-NULL) call the relevant destructor routine, supplying the address of the thread specific data as an argument. The tricky part to all this is figuring out when to call the routine that invokes the destructors. If you have complete control

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123