fixed GH #2058: Synchronization issue in Poco::Util::Timer at destruction

This commit is contained in:
Günter Obiltschnig
2018-03-06 17:33:02 +01:00
parent f352f61e5b
commit d73bb2ea86
3 changed files with 86 additions and 33 deletions

View File

@@ -83,6 +83,19 @@ public:
bool execute()
{
// Check if there's a StopNotification pending.
Poco::AutoPtr<TimerNotification> pNf = static_cast<TimerNotification*>(queue().dequeueNotification());
while (pNf)
{
if (pNf.cast<StopNotification>())
{
queue().clear();
_finished.set();
return false;
}
pNf = static_cast<TimerNotification*>(queue().dequeueNotification());
}
queue().clear();
_finished.set();
return true;

View File

@@ -224,6 +224,42 @@ void TimerTest::testCancel()
}
void TimerTest::testCancelAllStop()
{
{
Timer timer;
TimerTask::Ptr pTask = new TimerTaskAdapter<TimerTest>(*this, &TimerTest::onTimer);
timer.scheduleAtFixedRate(pTask, 5000, 5000);
Poco::Thread::sleep(100);
timer.cancel(false);
}
assert (true); // don't hang
}
void TimerTest::testCancelAllWaitStop()
{
{
Timer timer;
TimerTask::Ptr pTask = new TimerTaskAdapter<TimerTest>(*this, &TimerTest::onTimer);
timer.scheduleAtFixedRate(pTask, 5000, 5000);
Poco::Thread::sleep(100);
timer.cancel(true);
}
assert (true); // don't hang
}
void TimerTest::setUp()
{
}
@@ -252,6 +288,8 @@ CppUnit::Test* TimerTest::suite()
CppUnit_addTest(pSuite, TimerTest, testScheduleIntervalClock);
CppUnit_addTest(pSuite, TimerTest, testScheduleAtFixedRate);
CppUnit_addTest(pSuite, TimerTest, testCancel);
CppUnit_addTest(pSuite, TimerTest, testCancelAllStop);
CppUnit_addTest(pSuite, TimerTest, testCancelAllWaitStop);
return pSuite;
}

View File

@@ -33,6 +33,8 @@ public:
void testScheduleIntervalTimestamp();
void testScheduleIntervalClock();
void testCancel();
void testCancelAllStop();
void testCancelAllWaitStop();
void setUp();
void tearDown();