#include <stdio.h>
#include <pthread.h>
struct message {
int i;
int j;
};
void *func_detach (struct message *str)
{
printf ("%d\n", str->i);
sleep (10);
printf ("%d\n", str->j);
}
int main (int argc, char **argv)
{
struct message test;
pthread_t thread_id;
test.i = 10;
test.j = 20;
pthread_create (&thread_id, NULL, (void *)*func_detach, &test);
printf ("不用 pthread_join(),子线程就不能执行完毕,主线程先行结束\n");
return (0);
}
./ptread_detach
不用 pthread_join(),子线程就不能执行完毕,主线程先行结束
10
10
./ptread_detach
不用 pthread_join(),子线程就不能执行完毕,主线程先行结束
10
10
./ptread_detach
不用 pthread_join(),子线程就不能执行完毕,主线程先行结束
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |