[ 
https://issues.apache.org/jira/browse/PROTON-2438?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17815538#comment-17815538
 ] 

ASF GitHub Bot commented on PROTON-2438:
----------------------------------------

zlomek commented on code in PR #379:
URL: https://github.com/apache/qpid-proton/pull/379#discussion_r1482476356


##########
cpp/src/proactor_container_impl.cpp:
##########
@@ -532,7 +540,13 @@ void container::impl::run_timer_jobs() {
     // We've now taken the tasks to run from the deferred tasks
     // so we can run them unlocked
     // NB. We copied the due tasks in reverse order so execute from end
-    for (int i = tasks.size()-1; i>=0; --i) tasks[i].task();
+
+    for (int i = tasks.size()-1; i>=0; --i) {
+        if(is_active_.count(tasks[i].w_handle)) {
+            tasks[i].task();
+            is_active_.erase(tasks[i].w_handle);

Review Comment:
   ```
   void container::impl::run_timer_jobs() {
       std::vector<work> tasks;
   
       // We first extract all the runnable tasks and then run them -  this is 
to avoid having tasks
       // injected as we are running them (which could potentially never end)
       {
           GUARD(deferred_lock_);
   
           // Figure out how many tasks we need to execute and pop them to the 
back of the queue
           for (timestamp now = timestamp::now(); deferred_.size() > 0; 
deferred_.pop_back()) {
               // Is the next task in the future?
               timestamp next_time = deferred_.front().time;
               if ( next_time>now ) {
                   pn_proactor_set_timeout(proactor_, 
(next_time-now).milliseconds());
                   break;
               }
   
               std::pop_heap(deferred_.begin(), deferred_.end());
   
               if (is_active_.erase(deferred_.back().w_handle))
                   tasks.push_back(std::move(deferred_.back().task));
           }
       }
   
       // We've now taken the tasks to run from the deferred tasks
       // so we can run them unlocked
       for (work task : tasks) task();
   }
   ```





> [cpp] Cancellable tasks
> -----------------------
>
>                 Key: PROTON-2438
>                 URL: https://issues.apache.org/jira/browse/PROTON-2438
>             Project: Qpid Proton
>          Issue Type: Improvement
>          Components: cpp-binding
>            Reporter: Božo Dragojevič
>            Assignee: Rakhi Kumari
>            Priority: Major
>             Fix For: proton-c-0.38.0
>
>
> Allow scheduled tasks to be cancelled.
> A cancelled task does not keep reactor from stoping running



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org
For additional commands, e-mail: dev-h...@qpid.apache.org

Reply via email to