我有线程,每个都会打印一个字符串。代码编译,但当我运行它崩溃,甚至不打印一个字符。我的代码中是否存在任何组织错误?任何的想法?谢谢。我检查了几个网站,但没有任何意义。我正在使用VS C ++ 2013
void threadWork (void) const {
for (unsigned i = 0; i < 4; ++i) {
this_thread::sleep_for(chrono::milliseconds(_sleep_time(_dre)));
EnterCriticalSection(&criticalSection);
if ( boolVar = false)
{
InitializeConditionVariable(&conditionVariable);
InitializeCriticalSection(&criticalSection);
boolVar = true;
}
inUse = true;
while (inUse == true)
{
SleepConditionVariableCS(&conditionVariable, &criticalSection, INFINITE);
for (auto c : _printMe) {
this_thread::sleep_for(chrono::milliseconds(_sleep_time(_dre)));
cout << c;
cout.flush();
}
inUse = false;
LeaveCriticalSection(&criticalSection);
WakeAllConditionVariable(&conditionVariable);
}
}
};