From loschert@test.accucount.com  Wed Aug 12 19:07:28 1998
Received: from test.accucount.com (test.accucount.com [209.50.225.55])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id TAA20558
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Aug 1998 19:07:26 -0700 (PDT)
          (envelope-from loschert@test.accucount.com)
Received: (from loschert@localhost)
	by test.accucount.com (8.8.8/8.8.8) id WAA00865;
	Wed, 12 Aug 1998 22:06:55 GMT
	(envelope-from loschert)
Message-Id: <199808122206.WAA00865@test.accucount.com>
Date: Wed, 12 Aug 1998 22:06:55 GMT
From: loschert@servint.com
Reply-To: loschert@servint.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: Pthreads Bug - Interaction between printf and pthread_self
X-Send-Pr-Version: 3.2

>Number:         7600
>Category:       misc
>Synopsis:       Pthreads Bug - Interaction between printf and pthread_self
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Aug 12 19:10:01 PDT 1998
>Closed-Date:    Thu Dec 10 16:53:17 PST 1998
>Last-Modified:  Thu Dec 10 16:53:50 PST 1998
>Originator:     Matt Loschert
>Release:        FreeBSD 2.2.7-STABLE i386
>Organization:
ServInt Internet Services
>Environment:

FreeBSD 2.2.7-STABLE #0: Thu Jul 23 10:04:36 GMT 1998

>Description:

While testing a couple of server apps that I had written, I discovered that in certain situations, the process would "run-away".  At that point, the app could only be killed with a kill -9 and top would show that the process was eating up 99.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 exiting 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 not 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 <stdio.h>
#include <unistd.h>
#include <pthread.h>

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----




>Fix:
	
Don't know, hope this helps though.

>Release-Note:
>Audit-Trail:

From: Jin Guojun (ITG staff) <jin@george.lbl.gov>
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 <stdio.h>
 > #include <unistd.h>
 > #include <pthread.h>
 >  
 > 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----

From: Matthew Loschert <loschert@loschert.com>
To: FreeBSD-gnats-submit@FreeBSD.ORG
Cc:  Subject: Re: misc/7600: Pthreads Bug - Interaction between printf and pthread_self
Date: Thu, 13 Aug 1998 15:59:23 -0400 (EDT)

 I don't know if this helps at all, but when I was originally performing
 these tests, I was using tcsh as the shell.
 
 I am pretty much a unix newbie, so I don't really know what the important
 issues of an OS-related bug are.  I would like to help though, so if
 anyone wants to point me in the right direction in terms of what testing
 details to document, feel free.
 
     - Matt
 
 
 On Thu, 13 Aug 1998, Jin Guojun wrote:
 
 > The following reply was made to PR misc/7600; it has been noted by GNATS.
 > 
 > From: Jin Guojun (ITG staff) <jin@george.lbl.gov>
 > 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 <stdio.h>
 >  > #include <unistd.h>
 >  > #include <pthread.h>
 >  >  
 >  > 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
 > 
 
 
 
State-Changed-From-To: open->closed 
State-Changed-By: steve 
State-Changed-When: Thu Dec 10 16:53:17 PST 1998 
State-Changed-Why:  
Confirmed fixed in 2.2.8-RELEASE by originator.  Thanks again Matt! 
>Unformatted:
