From owner-freebsd-hackers Sun Dec 26 20:26:41 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from fremont.bolingbroke.com (adsl-216-102-90-210.dsl.snfc21.pacbell.net [216.102.90.210]) by hub.freebsd.org (Postfix) with ESMTP id 9FBE314D77 for ; Sun, 26 Dec 1999 20:26:39 -0800 (PST) (envelope-from ken@bolingbroke.com) Received: from localhost (ken@localhost) by fremont.bolingbroke.com (Pro-8.9.3/Pro-8.9.3) with ESMTP id UAA48434; Sun, 26 Dec 1999 20:26:32 -0800 (PST) Date: Sun, 26 Dec 1999 20:26:32 -0800 (PST) From: Ken Bolingbroke X-Sender: ken@fremont.bolingbroke.com To: Steffen Merkel Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Posix Threads In-Reply-To: <000c01bf4fa5$44bf5050$0201a8c0@blade> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 > #include > #include > > 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