This is the mail archive of the mailing list for the eCos project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pthread_exit() and tss destructors

On Wed, 2002-02-27 at 14:05, Nick Garnett wrote:


> It is my reading of the standard that it is the responsibility of the
> destructor function itself to set the value to NULL, or some other
> value. Otherwise there would be no need for {PTHREAD_DESTRUCTOR_ITERATIONS}.

The edition of POSIX 1003.1 (2001) I'm referring to mentions this in the
description of pthread_key_create():

    "An optional destructor function may be associated with each key
    value. At thread exit, if a key value has a non-NULL destructor
    pointer, and the thread has a non-NULL value associated with that
    key, the value of the key is set to NULL, and then the function
    pointed to is called with the previously associated value as its
    sole argument. The order of destructor calls is unspecified if more
    than one destructor exists for a thread when it exits."
This seems more natural and less error prone than expecting each
destructor to do it itself since in most of the cases, a destructor will
run only one time. I suppose then that {PTHREAD_DESTRUCTOR_ITERATIONS}
becomes useful when a destructor rebinds a key with a non-NULL value.



Before posting, please read the FAQ:
and search the list archive:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]