Intel TBB vs Boost

but do threading library even need to worry about the allocation of threads to cores. isn’t this a job of operating system? So what is the real Benifit of using TBB over Boost? You are right, a threading library usually should not care about mapping threads to cores. And TBB does not. TBB operates with … Read more

shared_ptr Assertion px != 0 failed

There should be no problem with using boost::shared_ptr as long as you initialize your shared pointers correctly and use the same memory management context for all your shared object libraries. In your case you are trying to use an uninitialized shared pointer. boost::shared_ptr<Obj> obj; obj->Something(); // assertion failed boost::shared_ptr<Obj> obj(new Obj); obj->Something(); // ok I … Read more

C++ Thread Pool [closed]

I think it is still not accepted into Boost, but a good staring point: threadpool. Some example of usage, from the web site: #include “threadpool.hpp” using namespace boost::threadpool; // Some example tasks void first_task() { … } void second_task() { … } void third_task() { … } void execute_with_threadpool() { // Create a thread pool. … Read more

How to create a thread pool using boost in C++?

The process is pretty simple. First create an asio::io_service and a thread_group. Fill the thread_group with threads linked to the io_service. Assign tasks to the threads using the boost::bind function. To stop the threads (usually when you are exiting your program) just stop the io_service and join all threads. You should only need these headers: … Read more

Example for boost shared_mutex (multiple reads/one write)?

1800 INFORMATION is more or less correct, but there are a few issues I wanted to correct. boost::shared_mutex _access; void reader() { boost::shared_lock< boost::shared_mutex > lock(_access); // do work here, without anyone having exclusive access } void conditional_writer() { boost::upgrade_lock< boost::shared_mutex > lock(_access); // do work here, without anyone having exclusive access if (something) { … Read more

C++0x has no semaphores? How to synchronize threads?

You can easily build one from a mutex and a condition variable: #include <mutex> #include <condition_variable> class semaphore { std::mutex mutex_; std::condition_variable condition_; unsigned long count_ = 0; // Initialized as locked. public: void release() { std::lock_guard<decltype(mutex_)> lock(mutex_); ++count_; condition_.notify_one(); } void acquire() { std::unique_lock<decltype(mutex_)> lock(mutex_); while(!count_) // Handle spurious wake-ups. condition_.wait(lock); –count_; } bool … Read more