static void run(std::shared_ptr<queue_type> const& queue,
                    std::shared_ptr<boost::asynchronous::lockfree_queue<boost::asynchronous::any_callable> > const& private_queue,
                    std::shared_ptr<diag_type> diagnostics,
                    std::shared_future<boost::thread*> self,
                    std::weak_ptr<this_type> this_,
                    size_t index)
    {
        boost::thread* t = self.get();
        boost::asynchronous::detail::single_queue_scheduler_policy<Q>::m_self_thread.reset(new thread_ptr_wrapper(t));
        // thread scheduler => tss
        boost::asynchronous::any_weak_scheduler<job_type> self_as_weak = boost::asynchronous::detail::lockable_weak_scheduler<this_type>(this_);
        boost::asynchronous::get_thread_scheduler<job_type>(self_as_weak,true);

        std::list<boost::asynchronous::any_continuation>& waiting =
                boost::asynchronous::get_continuations(std::list<boost::asynchronous::any_continuation>(),true);

        CPULoad cpu_load;
        while(true)
        {
            try
            {
                {
                    bool popped = execute_one_job(queue,cpu_load,diagnostics,waiting,index);
                    if (!popped)
                    {
                        cpu_load.loop_done_no_job();
                        // nothing for us to do, give up our time slice
                        boost::this_thread::yield();
                    }
                    // check for shutdown
                    boost::asynchronous::any_callable djob;
                    popped = private_queue->try_pop(djob);
                    if (popped)
                    {
                        djob();
                    }
                } // job destroyed (for destruction useful)
                // check if we got an interruption job
                boost::this_thread::interruption_point();
            }
            catch(boost::asynchronous::detail::shutdown_exception&)
            {
                // we are done, execute jobs posted short before to the end, then shutdown
                while(execute_one_job(queue,cpu_load,diagnostics,waiting,index));
                delete boost::asynchronous::detail::single_queue_scheduler_policy<Q>::m_self_thread.release();
                return;
            }
            catch(boost::thread_interrupted&)
            {
                // task interrupted, no problem, just continue
            }
            catch(std::exception&)
            {
                // TODO, user-defined error
            }
        }
    }
예제 #2
0
int factorial2(std::shared_future<int> f)
{
    int n = f.get();
    int result = 1;
    for (int i = 1; i <= n; ++i)
        result *= i;

    return result;
}
 //Get value and sync
 const T& get() {
     return _future.get();
 };
예제 #4
0
	void get_wait(typename std::enable_if<std::is_void<S>::value>::type* = nullptr) const {
		future.get();
		f.wait_idle();
	}
예제 #5
0
	decltype(auto) get_wait(typename std::enable_if<!std::is_void<S>::value>::type* = nullptr) const {
		auto& val = future.get();
		f.wait_idle();
		return val;
	}