<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - pthread_key_create aborts program instead of returning an error"
   href="http://llvm.org/bugs/show_bug.cgi?id=15431">15431</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>pthread_key_create aborts program instead of returning an error
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.2
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>hhinnant@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>d.frey@gmx.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I created a small test program that checks if pthread_key_create returns with
an error when too many keys are created:

#include <stdexcept>
#include <vector>
#include <pthread.h>

struct thread_specific
{
  pthread_key_t key_;
  thread_specific()
  {
    if( pthread_key_create( &key_, NULL ) != 0 ) {
      throw std::runtime_error( "pthread_key_create() failed" );
    }
  }
};

int main()
{
  std::vector< thread_specific > v;
  while( true ) {
    v.emplace_back( thread_specific() );
  }
}

The program throws the expected exception from the source with GCC 4.7 and with
Clang 3.2 with libstdc++. However, if I use libc++, the program is aborted
which I consider an error. Here's the output from my terminal, first the two
good-cases, last the bad-case:

$g++ -std=c++11 -pthread -O3 -Wall -Wextra t.cc -o t && ./t
terminate called after throwing an instance of 'std::runtime_error'
  what():  pthread_key_create() failed
Aborted (core dumped)
$clang++ -std=c++11 -pthread -O3 -Wall -Wextra t.cc -o t && ./t
terminate called after throwing an instance of 'std::runtime_error'
  what():  pthread_key_create() failed
Aborted (core dumped)
$clang++ -std=c++11 -stdlib=libc++ -pthread -O3 -Wall -Wextra t.cc -o t && ./t
cannot create pthread key for __cxa_get_globals()
Aborted (core dumped)
$

I'm on Ubuntu 12.10 (virtualized), Clang and libc++ installed via
ppa:georgekola/clang, libc++ has package version 1.0~svn170866-1~exp1ubuntu2.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>