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

Instrumented program hangs at exit if one of the threads is running getline() #454

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

Comments

@ramosian-glider
Copy link
Member

Originally reported on Google Code with ID 47

$ cat t.c
#include <pthread.h>
#include <stdio.h>

void *thread(void *unused) {
  char *line = NULL;
  size_t size;
  getline(&line, &size, stdin);
  return NULL;
}

int main() {
  pthread_t t;
  pthread_create(&t, NULL, thread, NULL);
  return 0;
}
$ clang t.c -o t -lpthread
$ ./t
(everything ok)
$ clang t.c -o t -lpthread -fsanitize=thread
% ./t
(hangs)

Reported by glider@google.com on 2014-02-06 11:59:54

@ramosian-glider
Copy link
Member Author

This happens because TSan calls fflush(0) at program shutdown, while the child thread
is holding a lock on the file stream.
Dima's suggestion is to replace the call to fflush(0) with "fflush(stdout); fflush(stderr);"

Reported by glider@google.com on 2014-02-06 12:15:09

@ramosian-glider
Copy link
Member Author

I don't see how I can make this test reliable enough to commit it.
Turns out that the program may exit before the call to getline(), and we can't synchronize
that call with the program exit, because getline() never ends.
I'm gonna submit the fix without this test.

Reported by glider@google.com on 2014-02-06 13:39:00

@ramosian-glider
Copy link
Member Author

sleep(1) will help you to write the test
also it's not necessary for a test to fail 100% of time

Reported by dvyukov@google.com on 2014-02-06 13:46:00

@ramosian-glider
Copy link
Member Author

Coped with an infinite loop in thread() instead of a sleep.
r200922 fixes the issue and r200923 adds the test.

Reported by glider@google.com on 2014-02-06 14:12:04

  • 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:31

  • 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