pthread_create创建线程

#include <stdio.h>
#include <pthread.h>

void *pthread_fun(void *arg)
{
	while (1) {
		sleep(1);
		printf("pthread running\n");
	}

	return((void *)0);
}

int main()
{
	pthread_t tid;
	pthread_create(&tid, NULL, pthread_fun, NULL);
//	pthread_create(&tid, NULL, &pthread_fun, NULL);

	while (1) {
		sleep(2);
		printf("main runing\n");
	}
	return 0;
}

 

编译 gcc test.c -lpthread

posted @ 2012-11-17 14:34  helloweworld  阅读(287)  评论(0编辑  收藏  举报