public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Weird bug in linux, glibc, gcc or what?
@ 2002-02-07 13:57 Felipe Contreras
  2002-02-08  9:48 ` Catalin Marinas
  2002-02-08 14:43 ` J.A. Magallon
  0 siblings, 2 replies; 3+ messages in thread
From: Felipe Contreras @ 2002-02-07 13:57 UTC (permalink / raw)
  To: LKML

Hi,

I've found a weird problem in linuxthreads. When I get out of a thread it
happends one of three, the new thread get's defuct and the proccess never
ends, it segfaults, or it works.

The most weird is that it depends on the kernel, and also when I run the
test trought gdb there is no problem.

Here is the test:

#include <pthread.h>

void *test(void *arg) {
	puts("Thread2");
	return 0;
}

int main() {
	pthread_t tt;
	puts("Before Thread2");
	pthread_create(&tt,NULL,test,NULL);
	puts("After Thread2");
	return 0;
}

The output:

1:src# ./test
Before Thread2
After Thread2
Thread2

This time it just kept waiting:

 8957 vc/1     00:00:00 test
 8958 ?        00:00:00 test <defunct>

I run it again:

1:src# ./test
Before Thread2
After Thread2

And again:

1:src# ./test
Before Thread2
Thread2
Segmentation fault

Now with gdb-5.1.1:

Starting program: /usr/src/./test
(no debugging symbols found)...[New Thread 1024 (LWP 9168)]
Before Thread2
[New Thread 2049 (LWP 9169)]
[New Thread 1026 (LWP 9170)]
Thread2
After Thread2

Program exited normally.

As I said the results vary from system to system, here are some
convinations:

* linux-2.4.10+glibc+2.2.4+gcc-2.95.3: Runs fine, but once in a while it
	keeps waiting for the defunct thread.

* linux-2.4.17+glibc+2.2.4+gcc-2.95.3: The same, but the defunct problem
	happends much more often.

* linux-2.4.10+glibc+2.2.5+gcc-3.0.3: Segfaults or waits for defuncts.

* linux-2.4.17+glibc+2.2.5+gcc-3.0.3: The same.

I'm lost on this, I supose it's a convination of glibc-linux problem.

Any ideas?

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Weird bug in linux, glibc, gcc or what?
  2002-02-07 13:57 Weird bug in linux, glibc, gcc or what? Felipe Contreras
@ 2002-02-08  9:48 ` Catalin Marinas
  2002-02-08 14:43 ` J.A. Magallon
  1 sibling, 0 replies; 3+ messages in thread
From: Catalin Marinas @ 2002-02-08  9:48 UTC (permalink / raw)
  To: Felipe Contreras; +Cc: LKML

On Thu, 7 Feb 2002, Felipe Contreras wrote:

> I've found a weird problem in linuxthreads. When I get out of a thread it
> happends one of three, the new thread get's defuct and the proccess never
> ends, it segfaults, or it works.
[snip]
> #include <pthread.h>
>
> void *test(void *arg) {
> 	puts("Thread2");
> 	return 0;
> }
>
> int main() {
> 	pthread_t tt;
> 	puts("Before Thread2");
> 	pthread_create(&tt,NULL,test,NULL);
> 	puts("After Thread2");
> 	return 0;
> }

Try this patch and see if it works:

--- thr_test.c	Fri Feb  8 09:45:35 2002
+++ thr_test1.c	Fri Feb  8 09:45:36 2002
@@ -10,5 +10,6 @@ int main() {
 	puts("Before Thread2");
 	pthread_create(&tt,NULL,test,NULL);
 	puts("After Thread2");
+	pthread_join(tt, NULL);
 	return 0;
 }

-- 
Catalin


________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information on a proactive anti-virus service working
around the clock, around the globe, visit http://www.messagelabs.com
________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Weird bug in linux, glibc, gcc or what?
  2002-02-07 13:57 Weird bug in linux, glibc, gcc or what? Felipe Contreras
  2002-02-08  9:48 ` Catalin Marinas
@ 2002-02-08 14:43 ` J.A. Magallon
  1 sibling, 0 replies; 3+ messages in thread
From: J.A. Magallon @ 2002-02-08 14:43 UTC (permalink / raw)
  To: Felipe Contreras; +Cc: LKML


On 20020207 Felipe Contreras wrote:
>Hi,
>
>I've found a weird problem in linuxthreads. When I get out of a thread it
>happends one of three, the new thread get's defuct and the proccess never
>ends, it segfaults, or it works.
>
>The most weird is that it depends on the kernel, and also when I run the
>test trought gdb there is no problem.
>
>Here is the test:
>
>#include <pthread.h>
>
>void *test(void *arg) {
>	puts("Thread2");
>	return 0;
>}
>
>int main() {
>	pthread_t tt;
>	puts("Before Thread2");
>	pthread_create(&tt,NULL,test,NULL);
>	puts("After Thread2");
>	return 0;
>}
>

Buggy program that could give unspecified behaviour, unless pthread
standard talks about orphaned threads...

Your main program can die (exit) before child thread ends, so it has
nobody to notify its dying or return to.

Try with a sleep(1) before main return, or better, do a
pthread_join().

-- 
J.A. Magallon                           #  Let the source be with you...        
mailto:jamagallon@able.es
Mandrake Linux release 8.2 (Cooker) for i586
Linux werewolf 2.4.18-pre9-slb #3 SMP Fri Feb 8 01:33:12 CET 2002 i686

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-02-08 14:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-02-07 13:57 Weird bug in linux, glibc, gcc or what? Felipe Contreras
2002-02-08  9:48 ` Catalin Marinas
2002-02-08 14:43 ` J.A. Magallon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox