0 Replies Latest reply: Jul 26, 2013 3:40 AM by 880893 RSS

    Race detection in child processes

    880893

      Hi,

       

      the program given below creates a child process with two threads accessing a shared variable. Unfortunately, Thread Analyzer does not detect the race (neither version 12.0 nor 12.3). The race is only detected if it occurs in the parent process. Option "-F on/all" to instrument child processes does not work in conjunction with option "-r all" (the collect tool emits the error message "

      Race-detection data cannot be collected with any of -F -j -J -x"). Is this an inherent limitation of Thread Analyzer or is there a way to detect races and deadlocks in child processes?

       

      Thank you very much in advance for your help.

      Regards

       

       

      #include <unistd.h>

      #include <stdlib.h>

      #include <assert.h>

      #include <pthread.h>

       

      int x;

       

      void* fun(void*)

      {

          x++;

          return NULL;

      }

       

      int main ()

      {

          x = 0;

         

          int pid = fork();

          assert(pid >= 0);

         

          if (pid == 0)

          {

              /* Child process */

              pthread_t thread;

              assert(pthread_create(&thread, NULL, fun, NULL) == 0);

              x++;

              assert(pthread_join(thread, NULL) == 0);

              _exit(0);

          }

          else

          {

              /* Parent process */

              sleep (1);

          }

       

          return 0;

      }