Date: Thu, 7 Nov 2002 14:53:30 +0300 (MSK) From: Maxim Konovalov <maxim@macomnet.ru> To: Mathieu Arnold <mat@mat.cc> Cc: freebsd-hackers@FreeBSD.org Subject: Re: pthreads on 4.7-RELEASE Message-ID: <20021107144845.Y18459-100000@news1.macomnet.ru> In-Reply-To: <180816670.1036672498@andromede.reaumur.absolight.net> References: <180816670.1036672498@andromede.reaumur.absolight.net>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <pthread.h>?
> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021107144845.Y18459-100000>
