Ignore:
Timestamp:
Jul 23, 2019, 5:05:09 AM (4 years ago)
Author:
Peter
Message:

Make the Scheduler recyclable i.e. allow jobs to be submitted also after wait() or interrupt() has been called. closes #916

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/Scheduler.cc

    r3826 r3828  
    5353  void Scheduler::interrupt(void)
    5454  {
     55    throw_if_error();
     56    if (!job_handler_.joinable())
     57      return;
     58
    5559    // first signal to JobHandler that Scheduler is waiting
    5660    boost::shared_ptr<Job> end;
     
    7276  {
    7377    throw_if_error();
     78    // if JobHandler is not joinable implies it is not executing,
     79    // launch a new thread executing a JobHandler.
     80    if (!job_handler_.joinable()) {
     81      assert(data_.jobs().empty());
     82      /*
     83        We cannot relaunch a thread, so instead we create a new thread
     84        and move its guts to our member variable, job_handler_.
     85        In c++11 we could do:
     86        job_handler_ = boost::thread(JobHandler(data_));
     87        but in c++98 we instead use swap
     88       */
     89      JobHandler tmp_handler(data_);
     90      boost::thread tmp(tmp_handler);
     91      swap(tmp, job_handler_);
     92    }
    7493    data_.jobs().push(job);
    7594  }
     
    99118  void Scheduler::wait(void)
    100119  {
     120    throw_if_error();
     121    if (!job_handler_.joinable())
     122      return;
     123
    101124    // first signal to JobHandler that Scheduler is waiting
    102125    boost::shared_ptr<Job> end;
Note: See TracChangeset for help on using the changeset viewer.