38 cout << *(
string *)arg << endl;
42 char *c =
new char[256];
44 strcpy(c,
"string from myfunc");
45 cout <<
"myfunc returning:" << c <<endl;
58 string *s =
new string(
"string from myfunc");
59 cout <<
"myfunc returning:" << *s <<endl;
77 void *return_value =
myfunc(arg);
78 pthread_exit(return_value);
81 int main(
int argc,
char *argv[])
90 string arg(
"string from main");
94 cout <<
"example 1:" << endl;
98 pthread_create(&tid, (pthread_attr_t *)NULL,
func, (
void *)&arg);
101 pthread_join(tid, ret);
105 char *pc = ((
char *)(
char *)*ret);
110 string *ps = ((
string *)(
string *)*ret);
122 cout <<
"\n" <<
"example 2:" << endl;
126 pthread_create(&tid, (pthread_attr_t *)NULL,
myfunc, (
void *)&arg);
129 pthread_join(tid, ret);
133 cout << ((
char *)(
char *)*ret) << endl;
134 delete ((
char *)(
char *)*ret);
137 cout << *((
string *)(
string *)*ret) << endl;
138 delete ((
string *)(
string *)*ret);
void * func(void *arg)
a function that calls the user defined function
void * myfunc(void *arg)
user defined function to call
int main(int argc, char *argv[])