Subject: kern/26567: closef deadlock with threads
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <yamt@mwd.biglobe.ne.jp>
List: netbsd-bugs
Date: 08/06/2004 15:42:53
>Number: 26567
>Category: kern
>Synopsis: closef deadlock with threads
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: kern-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Aug 06 06:44:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
>Release: NetBSD 2.0G
>Organization:
>Environment:
System: NetBSD kaeru 2.0G NetBSD 2.0G (build.kaeru) #1594: Thu Aug 5 06:34:13 JST 2004 takashi@kaeru:/home/takashi/work/kernel/build.kaeru i386
Architecture: i386
Machine: i386
>Description:
our descriptor handling code has an assumption that
a file is kept in a descriptor table during the most operations.
however, it no longer be held these days due to pthread and clone(2).
>How-To-Repeat:
run the following test code and see that
the main thread blocks at the first close(2) while
the test() thread blocks in read(2) forever.
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int fds[2];
void *
test(void *dummy)
{
char buf[1];
int rv;
rv = read(fds[0], buf, 1); /* WILL BLOCK HERE */
if (rv == 0) {
fprintf(stderr, "EOF\n");
} else if (rv == -1) {
perror("read");
exit(1);
} else {
fprintf(stderr, "%d\n", rv);
exit(1);
}
return NULL;
}
int
main()
{
pthread_t t;
if (pipe(fds)) {
perror("pipe");
exit(1);
}
if (pthread_create(&t, NULL, test, NULL)) {
perror("create");
exit(1);
}
fprintf(stderr, "sleep\n");
sleep(1);
fprintf(stderr, "close\n");
if (close(fds[0])) { /* WILL BLOCK HERE */
perror("close");
exit(1);
}
fprintf(stderr, "close writer\n");
if (close(fds[1])) {
perror("close");
exit(1);
}
fprintf(stderr, "join\n");
if (pthread_join(t, NULL)) {
perror("join");
exit(1);
}
exit(0);
}
>Fix:
unify f_count and f_usecount?
>Release-Note:
>Audit-Trail:
>Unformatted: