staticanalysis / data-race-test

Automatically exported from code.google.com/p/data-race-test
0 stars 0 forks source link

We should handle signal handlers as separate threads #46

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Example code with a data race (see the printf) which can't be found by 
ThreadSanitizer as of r2427:
===test.c===
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

pid_t child_pid = 0;
int ret = 0;

void child_handler(int signum) {
  if (signum == SIGCHLD && child_pid == 0) {
    printf("Whoops, PID shouldn't be 0!\n");
    ret = 1;
  }
}

int main(void) {
  signal(SIGCHLD, child_handler);
  child_pid = fork();
  if (child_pid == 0) {
    // in child 
    exit(0);
  }
  wait(NULL);
  return ret;
}
===========
$ gcc test.c
$ while ./a.out ; do echo "PASS"; done
PASS
...
PASS
Whoops, PID shouldn't be 0!

This test case was suggested by Denis Lunev

Original issue reported on code.google.com by timurrrr on 1 Sep 2010 at 1:07

GoogleCodeExporter commented 9 years ago
Test added to racecheck_unittest in r2428

Original comment by timurrrr on 1 Sep 2010 at 1:29