This is the mail archive of the cygwin mailing list for the Cygwin 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: why is pthread_key_create failing?


Dear Corinna,

Thank you for the rapid answer.

> The pthread_key_create function checks the incoming pthread_key_t pointer
> for being a valid object already and,if so, bails out with EBUSY.

The POSIX specification of this function [1] mentions that some value shall
be stored in *KEY but does not mention any meaning of *KEY upon entry to
the function. Therefore it's an output parameter, not an input-output parameter.
An implementation of the function can look at the value upon entry, and
decide to emit a message to a log file or something like that, but it should
not affect the function's return value.

Besides, code like this:

  pthread_key_create (pthread_key_t *key, void (*destructor) (void *))
  {
    if (pthread_key::is_good_object (key))
      return EBUSY;
    ...
  }

misunderstands the ::is_good_object function: It tests for a pointer that
points to a certain magic number. But there can also be other occurrences
of the value 0xdf0df047 in memory; if you find a pointer to this magic
number, it's likely but not guaranteed(!) that the value is a pthread_key_t
in use. I could easily construct a test case by filling large blocks of memory
with the word 0xdf0df047. This affects also the functions
  pthread_attr_init
  pthread_condattr_init
  pthread_rwlockattr_init
  pthread_mutexattr_init

Bruno


[1] http://www.opengroup.org/susv3/functions/pthread_key_create.html


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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