added support for starting functors/lambdas to Poco::Thread class

This commit is contained in:
Günter Obiltschnig
2014-11-16 20:43:19 +01:00
parent 28982f9fcc
commit 7043a3d4ff
8 changed files with 142 additions and 147 deletions

View File

@@ -363,6 +363,44 @@ void ThreadTest::testThreadFunction()
}
void ThreadTest::testThreadFunctor()
{
struct Functor
{
void operator () ()
{
++MyRunnable::_staticVar;
}
};
Thread thread;
assert (!thread.isRunning());
MyRunnable::_staticVar = 0;
thread.startFunc(Functor());
thread.join();
assert (1 == MyRunnable::_staticVar);
assert (!thread.isRunning());
#if __cplusplus >= 201103L
Thread thread2;
assert (!thread2.isRunning());
MyRunnable::_staticVar = 0;
thread.startFunc([] () {MyRunnable::_staticVar++;});
thread.join();
assert (1 == MyRunnable::_staticVar);
assert (!thread2.isRunning());
#endif
}
void ThreadTest::testThreadStackSize()
{
int stackSize = 50000000;
@@ -436,6 +474,7 @@ CppUnit::Test* ThreadTest::suite()
CppUnit_addTest(pSuite, ThreadTest, testTrySleep);
CppUnit_addTest(pSuite, ThreadTest, testThreadTarget);
CppUnit_addTest(pSuite, ThreadTest, testThreadFunction);
CppUnit_addTest(pSuite, ThreadTest, testThreadFunctor);
CppUnit_addTest(pSuite, ThreadTest, testThreadStackSize);
CppUnit_addTest(pSuite, ThreadTest, testSleep);