From owner-freebsd-hackers Thu Nov 7 3:53:38 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 58D4937B404 for ; Thu, 7 Nov 2002 03:53:36 -0800 (PST) Received: from relay1.macomnet.ru (relay1.macomnet.ru [195.128.64.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id ED78143E77 for ; Thu, 7 Nov 2002 03:53:34 -0800 (PST) (envelope-from maxim@macomnet.ru) Received: from news1.macomnet.ru (news1.macomnet.ru [195.128.64.14]) by relay1.macomnet.ru (8.11.6/8.11.6) with ESMTP id gA7BrUs3265438; Thu, 7 Nov 2002 14:53:30 +0300 (MSK) Date: Thu, 7 Nov 2002 14:53:30 +0300 (MSK) From: Maxim Konovalov To: Mathieu Arnold Cc: freebsd-hackers@FreeBSD.org Subject: Re: pthreads on 4.7-RELEASE In-Reply-To: <180816670.1036672498@andromede.reaumur.absolight.net> Message-ID: <20021107144845.Y18459-100000@news1.macomnet.ru> References: <180816670.1036672498@andromede.reaumur.absolight.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On 14:34+0300, Nov 7, 2002, Mathieu Arnold wrote: > Hi > > I'm having a bit of difficulties with pthreads, lets explain : > > $ cat test.c > #include "pthread.h" Shouldn't it be ? > void * test (void* t) { > while (1) { > printf("pouet"); Use printf("pouet\n") of fflush stdout. > sleep(1); > } > } > main () { > pthread_t th; > > if (pthread_create(&th, NULL, test, NULL)) { > perror("pthread_create"); > exit(1); > } > if (pthread_detach(th)) { > perror("pthread_detach"); > exit(2); > } > exit(0); Shouldn't it be pthread_exit(0) here? Your main thread can exits just before th gets a chance to run. > } > $ gcc -pthread -D_REENTRANT -D_THREAD_SAFE test.c -o test > $ ./test > pthread_create: Cannot allocate memory Anyway, can't reproduce: $ gcc -pthread -D_REENTRANT -D_THREAD_SAFE t.c -o t $ ./t $ uname -a FreeBSD spe151.testdrive.hp.com 4.7-RELEASE FreeBSD 4.7-RELEASE #0: Thu Oct 10 15:54:32 EDT 2002 root@spe151.testdrive.hp.com:/usr/obj/usr/src/sys/SMP i386 $ > I must be doing something stupid, but I cannot really find what... -- Maxim Konovalov, MAcomnet, Internet Dept., system engineer phone: +7 (095) 796-9079, mailto:maxim@macomnet.ru To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message