Exemplo n.º 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;
        }
    }
Exemplo n.º 2
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;
     }
 }
Exemplo n.º 3
0
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;
}