日期:2014-05-16 浏览次数:20682 次
#include "errno.h" #include "stdio.h" #include "stdlib.h" #include <pthread.h> #include "unistd.h" pthread_mutex_t hMutex = PTHREAD_MUTEX_INITIALIZER; void * threadFunc1(void *arg) { while(1) { sleep(10); (void)printf("aaa"); pthread_yield(); } return 0; } void * threadFunc2(void *arg) { while(1) { sleep(5); (void)printf("bbb"); pthread_yield(); } return 0; } int main(void) { pthread_t tid1, tid2; pthread_create(&tid1, NULL, threadFunc1, NULL); pthread_create(&tid2, NULL, threadFunc2, NULL); fflush(NULL); while(1) { sleep(1000); fflush(NULL); } return 0; }