Changeset 3948
- Timestamp:
- Jul 20, 2020, 9:12:46 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/priority_queue.cc
r3832 r3948 26 26 #include "Suite.h" 27 27 28 #include <boost/thread.hpp>29 30 28 #include <iostream> 29 #include <memory> 30 #include <thread> 31 #include <vector> 31 32 32 33 using namespace theplu::yat; … … 50 51 } 51 52 suite_.out() << str; 52 boost::this_thread::interruption_point();53 53 } 54 54 } … … 81 81 suite.out() << "popped one element in main thread: " << str << "\n"; 82 82 83 boost::thread_group workers;84 workers.create_thread(Worker(queue, suite));85 workers.create_thread(Worker(queue, suite));83 std::vector<std::thread> threads; 84 for (size_t i=0; i<2; ++i) 85 threads.push_back(std::thread(Worker(queue, suite))); 86 86 87 87 sleep(2); 88 88 queue.push("poison pill"); 89 89 90 workers.join_all();91 suite.out() << "\n";90 for (size_t i=0; i<threads.size(); ++i) 91 threads[i].join(); 92 92 93 93 typedef std::greater<std::string> MyComp; -
trunk/test/queue.cc
r3062 r3948 26 26 #include "yat/utility/Queue.h" 27 27 28 #include <boost/thread.hpp>29 30 28 #include <iostream> 29 #include <thread> 30 #include <vector> 31 31 32 32 using namespace theplu::yat; … … 50 50 } 51 51 sleep(1); 52 // Make sure we can be interrupted53 boost::this_thread::interruption_point();54 52 } 55 53 } … … 65 63 queue.push("Peter"); 66 64 67 boost::thread_group workers;68 workers.create_thread(Worker(queue));69 workers.create_thread(Worker(queue));70 workers.create_thread(Worker(queue));71 workers.create_thread(Worker(queue));65 std::vector<std::thread> threads; 66 threads.push_back(std::thread(Worker(queue))); 67 threads.push_back(std::thread(Worker(queue))); 68 threads.push_back(std::thread(Worker(queue))); 69 threads.push_back(std::thread(Worker(queue))); 72 70 73 workers.join_all(); 71 for (size_t i=0; i<threads.size(); ++i) 72 threads[i].join(); 74 73 75 74 Queue<std::string> queue2(queue); -
trunk/test/queue2.cc
r3063 r3948 26 26 #include "Suite.h" 27 27 28 #include <boost/thread.hpp>29 30 28 #include <iostream> 29 #include <thread> 30 #include <vector> 31 31 32 32 using namespace theplu::yat; … … 50 50 } 51 51 suite_.out() << str; 52 boost::this_thread::interruption_point();53 52 } 54 53 } … … 77 76 queue.push("!!!"); 78 77 79 boost::thread_group workers;80 workers.create_thread(Worker(queue, suite));81 workers.create_thread(Worker(queue, suite));78 std::vector<std::thread> threads; 79 threads.push_back(std::thread(Worker(queue, suite))); 80 threads.push_back(std::thread(Worker(queue, suite))); 82 81 83 82 sleep(2); 84 83 queue.push("poison pill"); 85 84 86 workers.join_all(); 85 for (size_t i=0; i<threads.size(); ++i) 86 threads[i].join(); 87 87 suite.out() << "\n"; 88 88 return suite.return_value(); -
trunk/yat/utility/Scheduler.cc
r3921 r3948 78 78 We cannot relaunch a thread, so instead we create a new thread 79 79 and move its guts to our member variable, job_handler_. 80 In c++11 we could have done:81 job_handler_ = boost::thread(JobHandler(data_));82 but in c++98 we instead use swap83 80 */ 84 JobHandler tmp_handler(data_); 85 boost::thread tmp(tmp_handler); 86 swap(tmp, job_handler_); 81 job_handler_ = std::thread(JobHandler(data_)); 87 82 } 88 83 data_.messengers().push(boost::make_shared<JobMessenger>(job)); … … 197 192 198 193 Scheduler::Job::status_type 199 Scheduler::Job::status(const boost::unique_lock<boost::mutex>& lock) const194 Scheduler::Job::status(const std::unique_lock<std::mutex>& lock) const 200 195 { 201 196 return status_; … … 203 198 204 199 205 void Scheduler::Job::status(const boost::unique_lock<boost::mutex>& lock,200 void Scheduler::Job::status(const std::unique_lock<std::mutex>& lock, 206 201 Scheduler::Job::status_type s) 207 202 { … … 243 238 // return job to scheduler 244 239 completed_.push(boost::make_shared<JobMessenger>(job)); 245 246 // Make sure we can be interrupted247 boost::this_thread::interruption_point();248 240 } 249 241 } … … 289 281 290 282 291 boost::mutex& Scheduler::Dependency::mutex(void)283 std::mutex& Scheduler::Dependency::mutex(void) 292 284 { 293 285 return mutex_; … … 425 417 void Scheduler::JobHandlerData::Count::decrement(void) 426 418 { 427 boost::unique_lock<boost::mutex> lock(mutex_);419 std::unique_lock<std::mutex> lock(mutex_); 428 420 assert(x_ > 0); 429 421 --x_; … … 433 425 int Scheduler::JobHandlerData::Count::get(void) const 434 426 { 435 boost::unique_lock<boost::mutex> lock(mutex_);427 std::unique_lock<std::mutex> lock(mutex_); 436 428 return x_; 437 429 } … … 440 432 void Scheduler::JobHandlerData::Count::increment(void) 441 433 { 442 boost::unique_lock<boost::mutex> lock(mutex_);434 std::unique_lock<std::mutex> lock(mutex_); 443 435 ++x_; 444 436 } … … 447 439 void Scheduler::JobHandlerData::Count::set(int x) 448 440 { 449 boost::unique_lock<boost::mutex> lock(mutex_);441 std::unique_lock<std::mutex> lock(mutex_); 450 442 x_ = x; 451 443 } … … 465 457 for (size_t i=0; i<n; ++i) { 466 458 Worker worker(data_->queue(), data_->messengers()); 467 workers_.push_back(boost::make_shared< boost::thread>(worker));459 workers_.push_back(boost::make_shared<std::thread>(worker)); 468 460 } 469 461 n_target_workers_ += n; … … 641 633 break; 642 634 } 643 644 // Make sure we can be interrupted645 boost::this_thread::interruption_point();646 635 } 647 636 -
trunk/yat/utility/Scheduler.h
r3918 r3948 27 27 28 28 #include <boost/exception_ptr.hpp> 29 #include <boost/thread.hpp>30 29 #include <boost/shared_ptr.hpp> 31 30 32 31 #include <list> 32 #include <mutex> 33 33 #include <set> 34 #include <thread> 34 35 #include <vector> 35 36 … … 116 117 friend class JobHandler; 117 118 void add_prerequisite(const boost::shared_ptr<Job>&, 118 const boost::unique_lock<boost::mutex>& lock);119 const std::unique_lock<std::mutex>& lock); 119 120 // \brief remove job from list of prerequisite 120 121 // \return number of prerequisite (after removal) 121 122 size_t remove_prerequisite(const boost::shared_ptr<Job>&, 122 const boost::unique_lock<boost::mutex>& lock);123 const std::unique_lock<std::mutex>& lock); 123 124 // set of jobs that have to finish before this can run 124 125 std::set<boost::shared_ptr<Job> > prerequisite_; … … 126 127 // functions below passing Dependency::Lock 127 128 std::set<boost::shared_ptr<Job> >& 128 prerequisite(const boost::unique_lock<boost::mutex>& lock);129 prerequisite(const std::unique_lock<std::mutex>& lock); 129 130 const std::set<boost::shared_ptr<Job> >& 130 prerequisite(const boost::unique_lock<boost::mutex>& lock) const;131 prerequisite(const std::unique_lock<std::mutex>& lock) const; 131 132 // - pristine is what it says 132 133 // - prepared - job has been either submitted directly a job that … … 136 137 enum status_type { pristine, prepared, running, completed}; 137 138 status_type status_; 138 status_type status(const boost::unique_lock<boost::mutex>& lock) const;139 void status(const boost::unique_lock<boost::mutex>& lock, status_type s);139 status_type status(const std::unique_lock<std::mutex>& lock) const; 140 void status(const std::unique_lock<std::mutex>& lock, status_type s); 140 141 unsigned priority_; 141 142 unsigned id_; … … 281 282 { 282 283 public: 283 typedef boost::unique_lock<boost::mutex> Lock;284 typedef std::unique_lock<std::mutex> Lock; 284 285 285 286 void add(const JobPtr& child, const JobPtr& parent, const Lock& lock); 286 287 void remove(const JobPtr& parent, const Lock& lock); 287 288 std::vector<JobPtr>& children(const JobPtr& key, const Lock& lock); 288 boost::mutex& mutex(void);289 private: 290 boost::mutex mutex_;289 std::mutex& mutex(void); 290 private: 291 std::mutex mutex_; 291 292 292 293 // job in key has to finish before jobs in vector … … 315 316 void set(int x); 316 317 private: 317 mutable boost::mutex mutex_;318 mutable std::mutex mutex_; 318 319 int x_; 319 320 }; … … 341 342 JobQueue queue_; 342 343 343 boost::mutex mutex_;344 std::mutex mutex_; 344 345 345 346 Count running_jobs_; … … 384 385 385 386 void send2queue(JobPtr& job, 386 const boost::unique_lock<boost::mutex>& lock);387 const std::unique_lock<std::mutex>& lock); 387 388 388 389 JobHandlerData* data_; … … 391 392 void join_workers(void); 392 393 393 typedef std::list<boost::shared_ptr< boost::thread> > WorkerList;394 typedef std::list<boost::shared_ptr<std::thread> > WorkerList; 394 395 // We keep workers here (rather than in JobHandler::operator() 395 396 // scope), so we can access it from other functions and don't … … 403 404 void throw_if_error(void) const; 404 405 405 mutable boost::mutex mutex_;406 mutable std::mutex mutex_; 406 407 JobHandlerData data_; 407 boost::thread job_handler_;408 std::thread job_handler_; 408 409 }; // end class Scheduler 409 410
Note: See TracChangeset
for help on using the changeset viewer.