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
[EMAIL PROTECTED]:/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 [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to