This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc 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]

[Bug nptl/4938] New: Threads evaporated by fork can have thread-specific values reused by new threads


When fork() is used in a program with multiple threads, and the child process
creates a new thread, the new thread can inherit thread-specific values of some
threads evaporated by fork(), instead of being initialized to NULL.

Sample program:

#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>

pthread_key_t key;

void *thread_body(void *arg) {
   printf("%p %p\n", pthread_self(), pthread_getspecific(key));
   pthread_setspecific(key, (void *)7);
   sleep(2);
}

int main(void) {
   pthread_t th;
   pthread_key_create(&key, NULL);
   pthread_create(&th, NULL, thread_body, NULL);
   sleep(1);
   if (fork() == 0) {
      pthread_create(&th, NULL, thread_body, NULL);
      sleep(1);
      exit(0);
   }
   sleep(2);
   return 0;
}

Actual result:

0xb7d7fb90 (nil)
0xb7d7fb90 0x7

Expected:

0xb7d7fb90 (nil)
0xb7d7fb90 (nil)

-- 
           Summary: Threads evaporated by fork can have thread-specific
                    values reused by new threads
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: nptl
        AssignedTo: drepper at redhat dot com
        ReportedBy: qrczak at knm dot org dot pl
                CC: glibc-bugs at sources dot redhat dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://sourceware.org/bugzilla/show_bug.cgi?id=4938

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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