Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signals that arrive during pthread_cond_wait are never delivered #498

Closed
ramosian-glider opened this issue Sep 1, 2015 · 3 comments
Closed

Comments

@ramosian-glider
Copy link
Member

Originally reported on Google Code with ID 91

What steps will reproduce the problem?

#include <pthread.h>
#include <signal.h>
#include <unistd.h>

int g_thread_run = 1;
pthread_mutex_t mutex;
pthread_cond_t cond;
int g_signal_count = 0;

void sig_handler(int signum) {
  write(0, "sig\n", 4);
  __sync_fetch_and_add(&g_signal_count, 1);
}

void* my_thread(void* arg) {
  pthread_mutex_lock(&mutex);
  while (g_thread_run) {
    pthread_cond_wait(&cond, &mutex);
  }
  pthread_mutex_unlock(&mutex);
  return NULL;
}

int main(int argc, char**argv) {
  signal(SIGUSR1, &sig_handler);

  pthread_t thr;
  pthread_create(&thr, NULL, &my_thread, NULL);
  sleep(1); // wait for thread to get inside pthread_cond_wait
  pthread_kill(thr, SIGUSR1);

  while (__atomic_load_n(&g_signal_count, __ATOMIC_SEQ_CST) == 0) {
    ;
  }

  pthread_mutex_lock(&mutex);
  g_thread_run = 0;
  pthread_cond_signal(&cond);
  pthread_mutex_unlock(&mutex);
  void* ret;
  pthread_join(thr, &ret);
  return 0;
}


What is the expected output? What do you see instead?

todd@todd-ThinkPad-T540p:/tmp$ /home/todd/sw/clang-230631-2/bin/clang -o test test.c
-lpthread
todd@todd-ThinkPad-T540p:/tmp$ time ./test
sig

real    0m1.001s
user    0m0.000s
sys 0m0.001s
todd@todd-ThinkPad-T540p:/tmp$ /home/todd/sw/clang-230631-2/bin/clang -o test -fsanitize=thread
test.c -lpthread
todd@todd-ThinkPad-T540p:/tmp$ time ./test
<hangs forever>

What version of the product are you using? On what operating system?
todd@todd-ThinkPad-T540p:/tmp$ /home/todd/sw/clang-230631-2/bin/clang -v
clang version 3.7.0 (trunk 230631)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.1
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
(from the chromium toolchain)

Please provide any additional information below.


Reported by tlipcon on 2015-04-08 04:29:17

@ramosian-glider
Copy link
Member Author

Should actually rephrase the title a bit -- the signal does arrive, but only after pthread_cond_wait
returns. It looks like the pthread_cond_wait interceptor is missing a wrapping 'BlockingCall'
scope, perhaps?

Reported by tlipcon on 2015-04-08 04:35:28

@ramosian-glider
Copy link
Member Author

Thanks for the report!
Should be fixed by:
http://llvm.org/viewvc/llvm-project?view=revision&revision=234394

Reported by dvyukov@google.com on 2015-04-08 07:52:47

  • Status changed: Fixed

@ramosian-glider
Copy link
Member Author

Adding Project:ThreadSanitizer as part of GitHub migration.

Reported by glider@google.com on 2015-07-30 09:21:34

  • Labels added: ProjectThreadSanitizer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant