Basic Thread Management
struct thr_rtn {
int completed;
char in_msg[MAX_MSG];
char out_msg[MAX_MSG];
};
main()
{
pthread_t tid;
int return_val;
struct thr_rtn *ptr;
struct thr_rtn msg;
strcpy(msg.in_msg, "hello");
msg.completed = 0;
return_val = pthread_create(
&tid, NULL, thread1_func, &msg);
return_val = pthread_join(tid, &ptr);
/* Now, ptr == &msg,
ptr->completed == 1,
ptr->in_msg =="hello",
ptr->out_msg == "hello" */
exit(0);
}
void thread1_func(struct thr_rtn * msg)
{
strcpy(msg->out_msg,
msg->in_msg);
msg->completed = 1;
pthread_exit((void *) msg);
}