Skip site navigation (1)Skip section navigation (2)
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>

index | next in thread | raw e-mail

[-- Attachment #1 --]
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)
[-- Attachment #2 --]

#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;
}







help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?02060419204200.29291>