Am 04/15/2012 10:04 PM, schrieb jacob navia:
> Le 15/04/12 20:17, Marc a écrit :
>> jacob navia wrote:
>>
>>> The new standard has added _Exit() and quick_exit(), and a new list of
>>> functions to be called (different from the atexit() function we already
>>> know).
>>>
>>> OK, but what about "at_thread_exit()" ???
>>
>> You can pass a destructor argument to tss_create (a very C++ way of
>> doing things...).
> But that means that one of the big advantages of the at*.* functions is
> gone since you have to know the exit function at the start of the thread!
No, you can determine the specific function that is to be called from
the contents of the key. Something like
struct destructor {
tss_dtor_t func;
}
void call_destructor(void* dest) {
if (dest) {
tss_dtor_t d = dest;
tss_dtor_t func = d->func;
func();
}
}
tss_key_t key;
tss_create(&key, call_destructor);
...
static struct destructor dest = { .func = my_favorite_func };
tss_set(&key, &dest);
Obviously you can extend this scheme by making this a linked list of
such function pointers that are called in FIFO, LIFO or whatever
order.
But I agree that having the specification of such a thing in the
application code is suboptimal. A generic solution as for at_exit
would have been preferable.
Jens