From owner-freebsd-questions Tue Jun 4 10:12:52 2002 Delivered-To: freebsd-questions@freebsd.org Received: from Danovitsch.dnsq.org (b74143.upc-b.chello.nl [212.83.74.143]) by hub.freebsd.org (Postfix) with ESMTP id 48D4737B403 for ; Tue, 4 Jun 2002 10:12:44 -0700 (PDT) Received: from FreeBSD.Danovitsch.LAN (b83007.upc-b.chello.nl [212.83.83.7]) by Danovitsch.dnsq.org (8.11.3/8.11.3) with SMTP id g54HBEI57502; Tue, 4 Jun 2002 19:11:14 +0200 (CEST) (envelope-from Danovitsch@Danovitsch.dnsq.org) Content-Type: Multipart/Mixed; charset="iso-8859-1"; boundary="------------Boundary-00=_IUY62PIHVOVH4E4Q14FM" From: "Daan Vreeken [PA4DAN]" Reply-To: Danovitsch@Danovitsch.dnsq.org To: Sperber Subject: Re: pthreads & freebsd Date: Tue, 4 Jun 2002 19:20:42 +0200 X-Mailer: KMail [version 1.2] Cc: FreeBSD-Questions@FreeBSD.org MIME-Version: 1.0 Message-Id: <02060419204200.29291@FreeBSD.Danovitsch.LAN> Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --------------Boundary-00=_IUY62PIHVOVH4E4Q14FM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit On Tuesday 04 June 2002 14:42, you wrote: > Hi > > I'm having problems with pthreads in freebsd. Especially with the > parameters. I'm trying to call a function with a char * parameter, but the > ways I tried it yet didn't work. > I found some examples on the net, which where probably for linux > (-lpthread), and which didn't work either. > So lets say I have: > > void *my_function(char *my_parameter) > { > ... > > } > > and I want to create a thread with this function, how could that work? Have a look at this code : (also included as an attachment to avoid mail-spaghetti) -------- cut here -------- #include #include void TheThread (char *Text) { printf("text: %s\n",Text); pthread_exit("lalala"); } int main(int argc, char *argv[]) { pthread_t ThreadID; const char Hello[] = "Hello world!"; char *ReturnString; // Start the thread... pthread_create(&ThreadID,NULL,(pthread_startroutine_t)&TheThread,&Hello); // Wait for the thread to exit pthread_join(ThreadID,(void **)&ReturnString); printf("return value: %s\n",ReturnString); return 0; } -------- cut here -------- compile with : gcc -Wall -pthread test.c -o test grtz! -- Control the lights in my room: http://www.Danovitsch.dnsq.org/webcam Moo, ]:8) --------------Boundary-00=_IUY62PIHVOVH4E4Q14FM Content-Type: text/x-c++; charset="iso-8859-1"; name="test.c" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="test.c" CiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVkZSA8cHRocmVhZC5oPgoKdm9pZCBUaGVUaHJlYWQg KGNoYXIgKlRleHQpIHsKCglwcmludGYoInRleHQ6ICVzXG4iLFRleHQpOwoJCglwdGhyZWFkX2V4 aXQoImxhbGFsYSIpOwp9CgoKCmludCBtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pCnsKCXB0 aHJlYWRfdAkJVGhyZWFkSUQ7Cgljb25zdCBjaGFyCQlIZWxsb1tdID0gIkhlbGxvIHdvcmxkISI7 CgljaGFyCQkJKlJldHVyblN0cmluZzsKCQoKCS8vIFN0YXJ0IHRoZSB0aHJlYWQuLi4KCXB0aHJl YWRfY3JlYXRlKCZUaHJlYWRJRCxOVUxMLChwdGhyZWFkX3N0YXJ0cm91dGluZV90KSZUaGVUaHJl YWQsJkhlbGxvKTsKCgoJLy8gV2FpdCBmb3IgdGhlIHRocmVhZCB0byBleGl0CglwdGhyZWFkX2pv aW4oVGhyZWFkSUQsKHZvaWQgKiopJlJldHVyblN0cmluZyk7CgkKCXByaW50ZigicmV0dXJuIHZh bHVlOiAlc1xuIixSZXR1cm5TdHJpbmcpOwoJCglyZXR1cm4gMDsKfQoKCgoKCgoK --------------Boundary-00=_IUY62PIHVOVH4E4Q14FM-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message