一个简单的pthread的程序,先创建一个线程,然后等待它结束。
int main()
{
pthread_t tid;
int rval;
char buf[100];
/* create the thread which main function is funcl */
rval = pthread_create(&tid, NULL, funcl, (void *)message);
if (rval != 0)
{
err_print("pthread_create error");
}
printf("thread create success/n");
/* wait for the function */
rval = pthread_join(tid, (void **)&buf);
if (rval != 0)
{
err_print("pthread_join error");
}
printf("thread waited terminates/n");
}
int main()
{
pthread_t tid;
int rval;
char buf[100];
/* create the thread which main function is funcl */
rval = pthread_create(&tid, NULL, funcl, (void *)message);
if (rval != 0)
{
err_print("pthread_create error");
}
printf("thread create success/n");
/* wait for the function */
rval = pthread_join(tid, (void **)&buf);
if (rval != 0)
{
err_print("pthread_join error");
}
printf("thread waited terminates/n");
}