Changeset 3828


Ignore:
Timestamp:
Jul 23, 2019, 5:05:09 AM (3 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

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Makefile.am

    r3827 r3828  
    124124
    125125# tests not passing through yet
    126 XFAIL_TESTS = test/scheduler6.test
     126XFAIL_TESTS =
    127127
    128128DISTRIBUTED_TESTS = \
  • trunk/test/scheduler6.cc

    r3827 r3828  
    7474  }
    7575
     76  // just to test
     77  scheduler.interrupt();
    7678
    7779  return suite.return_value();
  • 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;
  • trunk/yat/utility/Scheduler.h

    r3826 r3828  
    7575     be accomplished by calling wait() or interrupt().
    7676
    77      \note Currently, the Scheduler cannot be recycled, i.e.,
    78      if wait(void) or interruped(void) have been called, the behaviour of
    79      submit() is undefined.
     77     \note Prior version 0.17 the Scheduler could not be recycled, i.e.,
     78     if wait(void) or interruped(void) had been called, the behaviour of
     79     submit() was undefined.
    8080
    8181     \since New in yat 0.13
Note: See TracChangeset for help on using the changeset viewer.