C++并发实战:一道google笔试题

2014-11-24 11:19:04 · 作者: · 浏览: 0
题目:有四个线程1、2、3、4。线程1的功能就是输出1,线程2的功能就是输出2,以此类推.........现在有四个文件ABCD。初始都为空。现要让四个文件呈如下格式:
A:1 2 3 4 1 2....
B:2 3 4 1 2 3....
C:3 4 1 2 3 4....

D:4 1 2 3 4 1....

c++11代码:

#include
  
   
#include
   
     #include
    
      #include
     
       #include
      
        using namespace std; #define LOOP 10 mutex m; condition_variable cond; int flag; void fun(int num){ for(int i=0;i
       
         lk(m); while(flag!=num) cond.wait(lk); cout<