Date: Sun, 26 Dec 1999 20:26:32 -0800 (PST) From: Ken Bolingbroke <hacker@bolingbroke.com> To: Steffen Merkel <d_f0rce@gmx.de> Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Posix Threads Message-ID: <Pine.BSF.4.05.9912262021510.31281-100000@fremont.bolingbroke.com> In-Reply-To: <000c01bf4fa5$44bf5050$0201a8c0@blade>
next in thread | previous in thread | raw e-mail | index | archive | help
When the main thread exits, all active threads are immediately terminated. Since your main subroutine has nothing after the pthread_create(), it immediately exits, thus your secondary thread has no chance to run. Add a delay at the end of the main thread to give the pthread_create() the time it needs, or just pthread_join() to wait until the secondary thread terminates. Ken Bolingbroke hacker@bolingbroke.com On Sun, 26 Dec 1999, Steffen Merkel wrote: > Hello, > > I'm learning C now for some weeks and today I wanted to program > POSIX threads. Unfortunately my source seems not to run. Could you > please have a look at my code and tell me whats wrong: > > #include <stdio.h> > #include <stdlib.h> > #include <pthread.h> > > void print( char *string ){ > fprintf(stderr,"String: %s\n",string); > } > > void main(void){ > pthread_t thread; > char string[] = "Hallo"; > > if( pthread_create( &thread, (const pthread_attr_t *)NULL, (void *)&print, > &string ) != 0 ){ > perror("pthread_create()"); > exit(EXIT_FAILURE); > } > > } 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?Pine.BSF.4.05.9912262021510.31281-100000>