- 论坛徽章:
- 0
|
代码如下:
- #include <stdio.h>
- #include <pthread.h>
- #include <stdlib.h>
- #include <unistd.h>
- void *startThreadOne(void *arg)
- {
- while(1)
- {
- printf("1"); //这里不加\n,在运行的时候就看不到输出
- sleep(3);
- }
- }
- void *startThreadTwo(void *arg)
- {
- while(1)
- {
- printf("2"); //同上
- sleep(5);
- }
- }
- int main()
- {
- pthread_t THREADiD;
- pthread_t THREADID;
- void *result;
- void *result1;
- pthread_create(&THREADiD, NULL, startThreadOne, NULL);
- pthread_create(&THREADID, NULL, startThreadTwo, NULL);
- printf("wait for thread to finish.\n");
- int res = pthread_join(THREADiD, &result);
- res = pthread_join(THREADID, &result1);
- if(res != 0)
- {
- perror("thread join error.\n");
- exit(EXIT_FAILURE);
- }
- }
复制代码 是输出缓存机制之类的东西吗? |
|