ultimatepp/autotest/CVariable/CVariable.cpp
cxl d02fe7d7c7 Creating the *real* autotest nest
git-svn-id: svn://ultimatepp.org/upp/trunk@7141 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2014-04-02 18:36:01 +00:00

43 lines
711 B
C++

#include <Core/Core.h>
using namespace Upp;
ConditionVariable cv;
Mutex mtx;
int count;
bool texit;
void WorkThread()
{
for(;;) {
Mutex::Lock __(mtx);
LOG("Before wait");
if(texit) break;
cv.Wait(mtx);
LOG("After wait");
if(texit) break;
count++;
}
LOG("Exiting work thread");
}
CONSOLE_APP_MAIN
{
Thread t[10];
for(int i = 0; i < 10; i++)
t[i].Run(callback(WorkThread));
for(int i = 0; i < 1000; i++) {
Mutex::Lock __(mtx);
cv.Signal();
}
{
Mutex::Lock __(mtx);
texit = true;
}
texit = true;
cv.Broadcast();
for(int i = 0; i < 10; i++)
t[i].Wait();
LOG(count);
LOG("======== OK");
}