c*******a 发帖数: 1879 | 1 【 以下文字转载自 JobHunting 讨论区 】
发信人: justicezyx (just), 信区: JobHunting
标 题: Re: 大家看看一个自称狗家码农写的代码 (转载)
发信站: BBS 未名空间站 (Sun Nov 19 17:50:19 2017, 美东)
几个细节,跟google c++代码要求差别比较大。
这个代码我是看不懂在做什么。
#include
#include
#include
using namespace std;
// using declarations on namespace is banned in google c++ code
class Solution
{ // this is not the style used in google, if you write c++ in google, I
feel very difficult to believe that you can resist the muscle memory and
uses a different style
// implicit access modifier is banned
mutex mutexa, mutexb,
// multiple variable on same line is banned
int N = 0;
void threada()
{
for (int i = 0; i < N; ++i)
{
mutexa.lock();
cout<<"A ";
cout<
mutexb.unlock();
}
}
void threadb()
{
for (int i = 0; i < N; ++i)
{
mutexb.lock();
cout<<"B ";
cout<
mutexc.unlock();
}
}
void threadc()
{
for (int i = 0; i < N; ++i)
{
mutexc.lock();
cout<<"C ";
cout<
mutexa.unlock();
}
}
public:
void solve(int n)
{
N = n;
mutexb.lock();
mutexc.lock();
cout<<"M "<
std::thread ta(threada, this);
std::thread tb(threadb, this);
std::thread tc(threadc, this);
ta.join();
tb.join();
tc.join();
}
};
int main()
{
Solution s;
s.solve(10);
//cout<
//cout<
} |
|