예제 #1
0
    void do_test(void (this_type::*test_func)())
    {
        Lock lock(m);

        locked=false;
        done=false;

        hpx::thread t(test_func,this);

        try
        {
            {
                boost::unique_lock<hpx::lcos::local::mutex> lk(done_mutex);
                HPX_TEST(done_cond.wait_for(lk,boost::chrono::seconds(2),
                                                 boost::bind(&this_type::is_done,this)));
                HPX_TEST(!locked);
            }

            lock.unlock();
            t.join();
        }
        catch(...)
        {
            lock.unlock();
            t.join();
            throw;
        }
    }
예제 #2
0
파일: apply_colocated.cpp 프로젝트: 41i/hpx
void receive_result(boost::int32_t i)
{
    hpx::util::spinlock::scoped_lock l(result_mutex);
    if (i > final_result)
        final_result = i;
    result_cv.notify_one();
}
예제 #3
0
 void relative_wait_until_with_predicate()
 {
     boost::unique_lock<hpx::lcos::local::spinlock> lock(mutex);
     if(cond_var.wait_for(lock,boost::posix_time::seconds(5),check_flag(flag)) && flag)
     {
         ++woken;
     }
 }
예제 #4
0
 void wait_with_predicate()
 {
     boost::unique_lock<hpx::lcos::local::spinlock> lock(mutex);
     cond_var.wait(lock,check_flag(flag));
     if(flag)
     {
         ++woken;
     }
 }
예제 #5
0
 void wait_without_predicate()
 {
     boost::unique_lock<hpx::lcos::local::spinlock> lock(mutex);
     while(!flag)
     {
         cond_var.wait(lock);
     }
     ++woken;
 }
예제 #6
0
 void wait_until_with_predicate()
 {
     boost::system_time const timeout=boost::get_system_time()+boost::posix_time::seconds(5);
     boost::unique_lock<hpx::lcos::local::spinlock> lock(mutex);
     if(cond_var.wait_until(lock,timeout,check_flag(flag)) && flag)
     {
         ++woken;
     }
 }
예제 #7
0
    void locking_thread_through_constructor()
    {
        Lock lock(m,boost::chrono::milliseconds(50));

        boost::lock_guard<hpx::lcos::local::mutex> lk(done_mutex);
        locked=lock.owns_lock();
        done=true;
        done_cond.notify_one();
    }
예제 #8
0
    void locking_thread()
    {
        Lock lock(m,boost::defer_lock);
        lock.try_lock_for(boost::chrono::milliseconds(50));

        boost::lock_guard<hpx::lcos::local::mutex> lk(done_mutex);
        locked=lock.owns_lock();
        done=true;
        done_cond.notify_one();
    }
예제 #9
0
    void wait_until_with_predicate()
    {
        boost::chrono::system_clock::time_point const timeout =
            boost::chrono::system_clock::now() + boost::chrono::milliseconds(5);

        boost::unique_lock<hpx::lcos::local::spinlock> lock(mutex);
        if(cond_var.wait_until(lock,timeout,check_flag(flag)) && flag)
        {
            ++woken;
        }
    }
예제 #10
0
    void wait_until_without_predicate()
    {
        boost::system_time const timeout=boost::get_system_time()+boost::posix_time::seconds(5);

        boost::unique_lock<hpx::lcos::local::spinlock> lock(mutex);
        while(!flag)
        {
            if(cond_var.wait_until(lock,timeout) == hpx::lcos::local::cv_status::timeout)
            {
                return;
            }
        }
        ++woken;
    }
예제 #11
0
    void wait(hpx::lcos::local::spinlock& local_mutex,
        hpx::lcos::local::condition_variable& local_cond_var, bool& running)
    {
        bool first = true;
        while (!flag)
        {
            // signal successful initialization
            if (first)
            {
                {
                    boost::lock_guard<hpx::lcos::local::spinlock> lk(local_mutex);
                    running = true;
                }

                first = false;
                local_cond_var.notify_all();
            }

            boost::unique_lock<hpx::lcos::local::spinlock> lk(mutex);
            cond_var.wait(mutex);
        }
        ++woken;
    }
예제 #12
0
    void wait_until_without_predicate()
    {
        boost::chrono::system_clock::time_point const timeout =
            boost::chrono::system_clock::now() + boost::chrono::milliseconds(5);

        boost::unique_lock<hpx::lcos::local::spinlock> lock(mutex);
        while(!flag)
        {
            if(cond_var.wait_until(lock,timeout) == hpx::lcos::local::cv_status::timeout)
            {
                return;
            }
        }
        ++woken;
    }
예제 #13
0
파일: apply_colocated.cpp 프로젝트: 41i/hpx
int hpx_main()
{
    hpx::id_type here = hpx::find_here();
    hpx::id_type there = here;
    if (hpx::get_num_localities_sync() > 1)
    {
        std::vector<hpx::id_type> localities = hpx::find_remote_localities();
        there = localities[0];
    }

    {
        increment_action inc;
        hpx::apply_colocated(inc, there, here, 1);
    }

    {
        hpx::unique_future<hpx::id_type> inc_f =
            hpx::components::new_<increment_server>(there);
        hpx::id_type where = inc_f.get();

        increment_action inc;
        hpx::apply_colocated(inc, where, here, 1);
    }

    {
        hpx::unique_future<hpx::id_type> inc_f =
            hpx::components::new_<increment_server>(there);
        hpx::id_type where = inc_f.get();

        hpx::apply_colocated<increment_action>(where, here, 1);
    }

    // finalize will synchronize will all pending operations
    int result = hpx::finalize();

    hpx::util::spinlock::scoped_lock l(result_mutex);
    result_cv.wait_for(result_mutex, boost::chrono::seconds(1),
        hpx::util::bind(std::equal_to<boost::int32_t>(), boost::ref(final_result), 3));

    HPX_TEST_EQ(final_result, 3);

    return result;
}