私は最初のスレッドチュートリアルを書くようになりました。 私は単一スレッドのプロデューサとコンシューマを作成しています。 まだ完了していません。同期が残っています。 しかし、それはコンパイルされていない、私はそのエラーがどのような議論が欠けているか間違っているかを理解していない。 以下は私のコードです。スレッドエラーC2064:termが0引数を取る関数に評価されない
#include<iostream>
#include<thread>
#include<sstream>
#include<list>
#include<mutex>
#include<Windows.h>
using namespace std;
#define BUCKET_LEN 5
HANDLE gMutex = NULL;
HANDLE gSemFull = NULL;
HANDLE gSemEmpty = NULL;
class producerConsumer {
long i;
list<wstring> que;
public:
producerConsumer() {
i = 0;
que.clear();
}
void produce();
void consumer();
void startProducerConsumer();
};
void producerConsumer::produce() {
std::wstringstream str;
str << "Producer[" <<"]\n";
que.push_back(str.str());
}
void producerConsumer::consumer() {
wstring s = que.front();
cout << "Consumer[" << "]";
wcout << " " << s;
que.pop_front();
}
void producerConsumer::startProducerConsumer() {
std::thread t1(&producerConsumer::produce);
std::thread t2(&producerConsumer::consumer);
t1.joinable() ? t1.join() : 1;
t2.joinable() ? t2.join() : 1;
}
int main()
{
gMutex = CreateMutex(NULL, FALSE, NULL);
if (NULL == gMutex) {
cout << "Failed to create mutex\n";
}
else {
cout << "Created Mutex\n";
}
producerConsumer p;
p.startProducerConsumer();
if (ReleaseMutex(gMutex)) {
cout << "Failed to release mutex\n";
}
else {
cout << "Relested Mutex\n";
}
gMutex = NULL;
system("pause");
return 0;
}
なぜCreateMutexを使用しますか? –