Issue 47 in thread-sanitizer: Instrumented program hangs at exit if one of the threads is running getline()

89 views
Skip to first unread message

thread-s...@googlecode.com

unread,
Feb 6, 2014, 6:59:57 AM2/6/14
to thread-s...@googlegroups.com
Status: Accepted
Owner: gli...@google.com
CC: dvyu...@google.com
Labels: Type-Defect Priority-Medium

New issue 47 by gli...@google.com: Instrumented program hangs at exit if
one of the threads is running getline()
http://code.google.com/p/thread-sanitizer/issues/detail?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)

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

thread-s...@googlecode.com

unread,
Feb 6, 2014, 7:15:22 AM2/6/14
to thread-s...@googlegroups.com

Comment #1 on issue 47 by gli...@google.com: Instrumented program hangs at
exit if one of the threads is running getline()
http://code.google.com/p/thread-sanitizer/issues/detail?id=47

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);"

thread-s...@googlecode.com

unread,
Feb 6, 2014, 8:39:12 AM2/6/14
to thread-s...@googlegroups.com

Comment #2 on issue 47 by gli...@google.com: Instrumented program hangs at
exit if one of the threads is running getline()
http://code.google.com/p/thread-sanitizer/issues/detail?id=47

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.

thread-s...@googlecode.com

unread,
Feb 6, 2014, 8:46:13 AM2/6/14
to thread-s...@googlegroups.com

Comment #3 on issue 47 by dvyu...@google.com: Instrumented program hangs at
exit if one of the threads is running getline()
http://code.google.com/p/thread-sanitizer/issues/detail?id=47

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

thread-s...@googlecode.com

unread,
Feb 6, 2014, 9:12:08 AM2/6/14
to thread-s...@googlegroups.com
Updates:
Status: Fixed

Comment #4 on issue 47 by gli...@google.com: Instrumented program hangs at
exit if one of the threads is running getline()
http://code.google.com/p/thread-sanitizer/issues/detail?id=47

Coped with an infinite loop in thread() instead of a sleep.
r200922 fixes the issue and r200923 adds the test.
Reply all
Reply to author
Forward
0 new messages