Date: Tue, 4 Jun 2002 19:20:42 +0200 From: "Daan Vreeken [PA4DAN]" <Danovitsch@Danovitsch.dnsq.org> To: Sperber <sperber@gmx.at> Cc: FreeBSD-Questions@FreeBSD.org Subject: Re: pthreads & freebsd Message-ID: <02060419204200.29291@FreeBSD.Danovitsch.LAN>
next in thread | raw e-mail | index | archive | help
--------------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 <stdio.h> #include <pthread.h> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?02060419204200.29291>