mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
Poco: fix endless execution of task that was cancelled before run() method
This commit is contained in:
parent
9c8697655e
commit
50c28f08b4
@ -26,6 +26,8 @@
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/Event.h"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
@ -140,7 +142,7 @@ private:
|
||||
std::string _name;
|
||||
TaskManager* _pOwner;
|
||||
float _progress;
|
||||
TaskState _state;
|
||||
std::atomic<TaskState> _state;
|
||||
Event _cancelEvent;
|
||||
mutable FastMutex _mutex;
|
||||
|
||||
|
@ -17,7 +17,8 @@
|
||||
#include "Poco/Task.h"
|
||||
#include "Poco/TaskManager.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <array>
|
||||
|
||||
namespace Poco {
|
||||
|
||||
@ -61,8 +62,17 @@ void Task::run()
|
||||
pOwner->taskStarted(this);
|
||||
try
|
||||
{
|
||||
_state = TASK_RUNNING;
|
||||
/** Task can be already cancelled.
|
||||
* To prevent endless executing already cancelled task _state is assigned to TASK_RUNNING only if _state != TASK_CANCELLING
|
||||
*/
|
||||
std::array<TaskState, 3> allowed_states{TASK_IDLE, TASK_STARTING, TASK_FINISHED};
|
||||
for (auto & expected : allowed_states)
|
||||
if (_state.compare_exchange_strong(expected, TASK_RUNNING))
|
||||
break;
|
||||
|
||||
if (_state == TASK_RUNNING)
|
||||
runTask();
|
||||
|
||||
}
|
||||
catch (Exception& exc)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user