From owner-freebsd-bugs Thu Aug 13 11:00:12 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id LAA09644 for freebsd-bugs-outgoing; Thu, 13 Aug 1998 11:00:12 -0700 (PDT) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id LAA09539 for ; Thu, 13 Aug 1998 11:00:04 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.8.8/8.8.5) id LAA28933; Thu, 13 Aug 1998 11:00:01 -0700 (PDT) Date: Thu, 13 Aug 1998 11:00:01 -0700 (PDT) Message-Id: <199808131800.LAA28933@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.ORG From: Jin Guojun (ITG staff) Subject: Re: misc/7600: Pthreads Bug - Interaction between printf and pthread_self Reply-To: Jin Guojun (ITG staff) Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR misc/7600; it has been noted by GNATS. From: Jin Guojun (ITG staff) To: FreeBSD-gnats-submit@FreeBSD.ORG, loschert@servint.com Cc: Subject: Re: misc/7600: Pthreads Bug - Interaction between printf and pthread_self Date: Thu, 13 Aug 1998 10:53:24 -0700 (PDT) The problem is no in "3 Exit the shell.". It is related to either rexec/rsh or xterm. I tried followings, and only exit xterm will cause the same problem: % sh $ ./bug & ^D % top # everything is OK % csh % ./bug & %^D % top # everything is OK % exit then log back in, bug is chewing CPU now. -Jin > >Description: > > While testing a couple of server apps that I had written, I discovered that in c > ertain situations, the process would "run-away". At that point, the app could o > nly be killed with a kill -9 and top would show that the process was eating up 9 > 9.9% of the cpu cycles. > > I found that the condition that instigated the problem was starting the app as a > background process and then exiting the shell. Almost immediately after exitin > g the shell, the process would go haywire. :) > > The apps use pthreads and therefore -libc_r. > > I attempted to isolate the problem this evening by stripping out extraneous code > . I was able to cut it down to the following program. The line that it does no > t like is the printf line that calls pthread_self to show the thread id. > > > >How-To-Repeat: > > 1. Compile the below code with the following command: > > gcc -Wall -o bug FILENAME.c -lc_r > > 2. Run the program in the background with: > > ./bug & > > 3. Exit the shell. > > 4. Log back in, check cpu usage with top. > > > > ----CODE BEGINS (FILENAME.c)---- > > > #include > #include > #include > > void *newthread (void *vptr); > > > int main() > { > pthread_t thread; > > pthread_create (&thread, NULL, newthread, NULL); > pthread_join (thread, NULL); > exit(0); > } > > > void *newthread(void *vptr) > { > for(;;) { > printf("Thread %d: Just looped again.\n", (int) pthread_self()); > sleep(5); > } > } > > > ----CODE ENDS---- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message