Changeset 3687


Ignore:
Timestamp:
Aug 26, 2017, 9:31:50 AM (3 months ago)
Author:
peter
Message:

Create thread_group inside the scope of operator() instead of as a
member. Having it as member did force us to using a
shared_ptr<thread_group>, which can now be avoided. Also, the
destruction of thread group occurs when leaving operator(), which is
easier to analyse than when it as a member occurred in JobHandler?
destructor.

Location:
trunk/yat/utility
Files:
2 edited

Legend:

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

    r3686 r3687  
    202202                                                                                                                                                running_jobs_type& running_jobs,
    203203                                                                                                                                                Queue<boost::exception_ptr>& error)
    204                 : workers_(new boost::thread_group),
     204                : threads_(threads),
    205205                        queue_(queue), jobs_(jobs), running_jobs_(running_jobs),
    206206                        error_(error), job_counter_(0)
    207207        {
    208                 for (size_t i=0; i<threads; ++i)
    209                         workers_->create_thread(Worker(queue_, jobs_));
    210208        }
    211209
     
    300298        void Scheduler::JobHandler::operator()(void)
    301299        {
     300                boost::thread_group workers;
     301                for (size_t i=0; i<threads_; ++i)
     302                        workers.create_thread(Worker(queue_, jobs_));
    302303                // Process jobs (in jobs_) coming both from Scheduler and
    303304                // completed jobs from Workers until Scheduler is waiting
     
    328329                                // For other cases (queue is not empty) send workers a
    329330                                // interrupt signal and wait for them to wrap up.
    330                                 workers_->interrupt_all();
     331                                workers.interrupt_all();
    331332                                return;
    332333                        }
     
    339340                boost::shared_ptr<Job> end;
    340341                queue_.push(end);
    341                 workers_->join_all();
     342                workers.join_all();
    342343        }
    343344
  • trunk/yat/utility/Scheduler.h

    r3685 r3687  
    238238                        void send2queue(JobPtr& job);
    239239                        // we need to be copyable
    240                         boost::shared_ptr<boost::thread_group> workers_;
     240                        unsigned int threads_;
    241241                        JobQueue& queue_;
    242242                        Queue<JobPtr>& jobs_;
Note: See TracChangeset for help on using the changeset viewer.