why is pthread_key_create failing?

Bruno Haible bruno@clisp.org
Wed Nov 7 03:12:00 GMT 2007


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/



More information about the Cygwin mailing list