Index: cpukit/posix/src/keysetspecific.c
===================================================================
--- cpukit/posix/src/keysetspecific.c	(revision 8e133b25005947879113a46cc33414dfbcce6123)
+++ cpukit/posix/src/keysetspecific.c	(revision 01f2337432d6a0ac92a022161370955172bc95fc)
@@ -38,4 +38,6 @@
   Objects_Locations            location;
   POSIX_Keys_Key_value_pair   *value_pair_ptr;
+  RBTree_Node                 *p;
+  POSIX_Keys_Key_value_pair    search_node;
 
   the_key = _POSIX_Keys_Get( key, &location );
@@ -43,29 +45,38 @@
 
     case OBJECTS_LOCAL:
-      value_pair_ptr = _POSIX_Keys_Key_value_pair_allocate();
+      search_node.key = key;
+      search_node.thread_id = _Thread_Executing->Object.id;
+      p = _RBTree_Find( &_POSIX_Keys_Key_value_lookup_tree,
+                                    &search_node.Key_value_lookup_node );
 
-      if ( !value_pair_ptr ) {
-        _Objects_Put( &the_key->Object );
+      if ( p ) {
+        value_pair_ptr = _RBTree_Container_of( p,
+                                          POSIX_Keys_Key_value_pair,
+                                          Key_value_lookup_node );
 
-        return ENOMEM;
+        value_pair_ptr->value = value;
+      } else {
+        value_pair_ptr = _POSIX_Keys_Key_value_pair_allocate();
+
+        if ( !value_pair_ptr ) {
+          _Objects_Put( &the_key->Object );
+
+          return ENOMEM;
+        }
+
+        value_pair_ptr->key = key;
+        value_pair_ptr->thread_id = _Thread_Executing->Object.id;
+        value_pair_ptr->value = value;
+        /* The insert can only go wrong if the same node is already in a unique
+         * tree. This has been already checked with the _RBTree_Find() */
+        (void) _RBTree_Insert( &_POSIX_Keys_Key_value_lookup_tree,
+                             &(value_pair_ptr->Key_value_lookup_node) );
+
+        /** append rb_node to the thread API extension's chain */
+        _Chain_Append_unprotected(
+          &_Thread_Executing->Key_Chain,
+          &value_pair_ptr->Key_values_per_thread_node
+        );
       }
-
-      value_pair_ptr->key = key;
-      value_pair_ptr->thread_id = _Thread_Executing->Object.id;
-      value_pair_ptr->value = value;
-      if ( _RBTree_Insert( &_POSIX_Keys_Key_value_lookup_tree,
-                           &(value_pair_ptr->Key_value_lookup_node) ) ) {
-        _Freechain_Put( (Freechain_Control *)&_POSIX_Keys_Keypool,
-                        (void *) value_pair_ptr );
-        _Objects_Put( &the_key->Object );
-
-        return EAGAIN;
-      }
-
-      /** append rb_node to the thread API extension's chain */
-      _Chain_Append_unprotected(
-        &_Thread_Executing->Key_Chain,
-        &value_pair_ptr->Key_values_per_thread_node
-      );
 
       _Objects_Put( &the_key->Object );
Index: testsuites/psxtests/psxkey05/init.c
===================================================================
--- testsuites/psxtests/psxkey05/init.c	(revision 8e133b25005947879113a46cc33414dfbcce6123)
+++ testsuites/psxtests/psxkey05/init.c	(revision 01f2337432d6a0ac92a022161370955172bc95fc)
@@ -53,4 +53,12 @@
   rtems_test_assert( *value == Data_array[1] );
 
+  puts( "Init - key1 pthread_setspecific - OK" );
+  sc = pthread_setspecific( key1, &Data_array[1] );
+  rtems_test_assert( !sc );
+
+  puts( "Init - key1 pthread_getspecific - OK" );
+  value = pthread_getspecific( key1 );
+  rtems_test_assert( *value == Data_array[1] );
+
   puts( "Init - pthread key1 delete - OK" );
   sc = pthread_key_delete( key1 );
Index: testsuites/psxtests/psxkey05/psxkey05.scn
===================================================================
--- testsuites/psxtests/psxkey05/psxkey05.scn	(revision 8e133b25005947879113a46cc33414dfbcce6123)
+++ testsuites/psxtests/psxkey05/psxkey05.scn	(revision 01f2337432d6a0ac92a022161370955172bc95fc)
@@ -9,4 +9,6 @@
 Init - key1 pthread_getspecific - OK
 Init - key2 pthread_getspecific - OK
+Init - key1 pthread_setspecific - OK
+Init - key1 pthread_getspecific - OK
 Init - pthread key1 delete - OK
 Init - pthread key2 delete - OK
