当前位置: 首页>>代码示例>>C++>>正文


C++ boost::barrier类代码示例

本文整理汇总了C++中boost::barrier的典型用法代码示例。如果您正苦于以下问题:C++ barrier类的具体用法?C++ barrier怎么用?C++ barrier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了barrier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: runner

void runner(std::size_t thread_index, boost::barrier& data_barrier, data_t& data) {
    for (std::size_t i = 0; i < 1000; ++ i) {
        fill_data(data.at(thread_index));
        data_barrier.wait();

        if (!thread_index) {
            compute_send_data(data);
        }
        data_barrier.wait();
    }
}
开发者ID:bonly,项目名称:exercise,代码行数:11,代码来源:20130120_barrier.cpp

示例2: evaluate

 std::pair<std::vector<unsigned> , unsigned> evaluate(unsigned num_iterations)
 {
     thread_num_iterations = num_iterations;
     thread_score = std::vector<unsigned>(def_decks.size(), 0u);
     thread_total = 0;
     thread_compare = false;
     // unlock all the threads
     main_barrier.wait();
     // wait for the threads
     main_barrier.wait();
     return(std::make_pair(thread_score, thread_total));
 }
开发者ID:catepillar,项目名称:tyrant_optimize_gui,代码行数:12,代码来源:tyrant_optimize.cpp

示例3: start

 bool start() {
   bool throws = false;
   t_ = std::thread([&]() {
     server_->start([&]() { barrier_.wait(); },
                    [&](std::exception_ptr /*ex*/) {
                      throws = true;
                      server_ = nullptr;
                      barrier_.wait();
                    });
   });
   barrier_.wait();
   return !throws;
 }
开发者ID:facebook,项目名称:proxygen,代码行数:13,代码来源:HTTPServerTest.cpp

示例4: compare

 std::pair<std::vector<unsigned> , unsigned> compare(unsigned num_iterations, double prev_score)
 {
     thread_num_iterations = num_iterations;
     thread_score = std::vector<unsigned>(def_decks.size(), 0u);
     thread_total = 0;
     thread_prev_score = prev_score;
     thread_compare = true;
     thread_compare_stop = false;
     // unlock all the threads
     main_barrier.wait();
     // wait for the threads
     main_barrier.wait();
     return(std::make_pair(thread_score, thread_total));
 }
开发者ID:catepillar,项目名称:tyrant_optimize_gui,代码行数:14,代码来源:tyrant_optimize.cpp

示例5: main

int main(int argc, char* argv[])
{
    if (argc < 2)
    {
        boost::filesystem::path exePath(argv[0]);
        std::cout << "usage: " << exePath.filename().string() << " <RTSP url of stream>" << std::endl;
        return -1;
    }
    
    boost::program_options::options_description desc("");
	desc.add_options()
		("no-display", "")
		("url", boost::program_options::value<std::string>(), "url")
		("interface", boost::program_options::value<std::string>(), "interface")
		("buffer-size", boost::program_options::value<unsigned long>(), "buffer-size");
    
    boost::program_options::positional_options_description p;
    p.add("url", -1);
    
    boost::program_options::variables_map vm;
    boost::program_options::store(boost::program_options::command_line_parser(argc, argv).
              options(desc).positional(p).run(), vm);
    boost::program_options::notify(vm);
    
    const char* interfaceAddress;
    if (vm.count("interface"))
    {
		interfaceAddress = vm["interface"].as<std::string>().c_str();
    }
    else
    {
		interfaceAddress = "0.0.0.0";
    }

	unsigned long bufferSize;
	if (vm.count("buffer-size"))
	{
		bufferSize = vm["buffer-size"].as<unsigned long>();
	}
	else
	{
		bufferSize = DEFAULT_SINK_BUFFER_SIZE;
	}

	std::cout << "Buffer size " << to_human_readable_byte_count(bufferSize, false, false) << std::endl;

	rtspClient = RTSPCubemapSourceClient::create(vm["url"].as<std::string>().c_str(), bufferSize, AV_PIX_FMT_RGBA, false, interfaceAddress);
    std::function<void (RTSPCubemapSourceClient*, CubemapSource*)> callback(boost::bind(&onDidConnect, _1, _2));
    rtspClient->setOnDidConnect(callback);
    rtspClient->connect();
    
    barrier.wait();
    
    Renderer renderer(cubemapSource);
	renderer.setOnDisplayedCubemapFace(boost::bind(&onDisplayedCubemapFace, _1, _2));
	renderer.setOnDisplayedFrame(boost::bind(&onDisplayedFrame, _1));
    renderer.start(); // Returns when window is closed
    
    CubemapSource::destroy(cubemapSource);
}
开发者ID:YunSuk,项目名称:AlloUnity,代码行数:60,代码来源:main.cpp

示例6:

 ~Process()
 {
     destroy_threads = true;
     main_barrier.wait();
     for(auto thread: threads) { thread->join(); }
     for(auto data: threads_data) { delete(data); }
 }
开发者ID:catepillar,项目名称:tyrant_optimize_gui,代码行数:7,代码来源:tyrant_optimize.cpp

示例7: wait_fn

void wait_fn( boost::barrier & b,
              boost::fibers::mutex & mtx,
              boost::fibers::condition_variable & cond,
              bool & flag) {
    b.wait();
	std::unique_lock< boost::fibers::mutex > lk( mtx);
	cond.wait( lk, [&flag](){ return flag; });
	++value;
}
开发者ID:alexeykuzmin0,项目名称:ThePlatform,代码行数:9,代码来源:test_condition_mt_post.cpp

示例8: invoke_n_workers

void invoke_n_workers(
    boost::barrier& b
    , double& elapsed
    , boost::uint64_t workers
)
{
    b.wait();

    invoke_n_workers_nowait(elapsed, workers);
}
开发者ID:akemp,项目名称:hpx,代码行数:10,代码来源:delay_baseline_threaded.cpp

示例9: fgThrow

static void
doit(const std::vector<const FgVariant*> & /*sources*/,
     const std::vector<FgVariant*> & /*sinks*/)
{
        // First wait for both threads to reach so we can force
        // one exception to be thrown first. Note that if you get
        // a deadlock here, something is seriously screwed :-)
    m_barrier.wait();
    fgThrow("Thrown from multiple threads at the same time!");
}
开发者ID:guozanhua,项目名称:FaceGenBaseLibrary,代码行数:10,代码来源:FgDepGraphTest.cpp

示例10: notify_all_fn

void notify_all_fn( boost::barrier & b,
                    boost::fibers::mutex & mtx,
                    boost::fibers::condition_variable & cond,
                    bool & flag) {
    b.wait();
	std::unique_lock< boost::fibers::mutex > lk( mtx);
    flag = true;
    lk.unlock();
	cond.notify_all();
}
开发者ID:alexeykuzmin0,项目名称:ThePlatform,代码行数:10,代码来源:test_condition_mt_post.cpp

示例11: thread_func_TestPercentiles

static void thread_func_TestPercentiles(boost::barrier& bar, MetricsFactory* factory, const char* name)
{
    Metric& metric = factory->get(name);
    bar.wait();
    for (int j=0; j < 25; j++) {
        double source[] = { 43, 54, 56, 61, 62, 66, 68, 69, 69, 70, 71, 72, 77, 78, 79, 85, 87, 88, 89, 93, 95, 96, 98, 99, 99 };
        for (size_t i=0; i < sizeof(source)/sizeof(*source); i++) {
            metric.update(source[i]);
        }
    }
}
开发者ID:michael-popov,项目名称:clockwork,代码行数:11,代码来源:utest_histogram_percentiles.cpp

示例12: thread_fun

//! This function is executed in multiple threads
void thread_fun(boost::barrier& bar)
{
    // Wait until all threads are created
    bar.wait();

    // Now, do some logging
    for (unsigned int i = 0; i < LOG_RECORDS_TO_WRITE; ++i)
    {
        BOOST_LOG(test_lg::get()) << "Log record " << i;
    }
}
开发者ID:avasopht,项目名称:boost_1_55_0-llvm,代码行数:12,代码来源:main.cpp

示例13: test

void test(unsigned int record_count, boost::barrier& bar)
{
    BOOST_LOG_SCOPED_THREAD_TAG("ThreadID", boost::this_thread::get_id());
    bar.wait();

    src::severity_logger< severity_level > slg;
    for (unsigned int i = 0; i < record_count; ++i)
    {
        BOOST_LOG_SEV(slg, warning) << "Test record";
    }
}
开发者ID:Adikteev,项目名称:rtbkit-deps,代码行数:11,代码来源:record_emission.cpp

示例14: thread_func_TestHistogram

static void thread_func_TestHistogram(boost::barrier& bar, MetricsFactory* factory, const char* name)
{
    Metric& metric = factory->get(name);
    bar.wait();
    for (int j=0; j < 100; j++) {
        metric.update(0);
        metric.update(1);
        metric.update(10);
        metric.update(30);
        metric.update(31);
    }
}
开发者ID:michael-popov,项目名称:clockwork,代码行数:12,代码来源:utest_histogram_percentiles.cpp

示例15: threadFunc

void threadFunc(FreeList& pool, ros::atomic<bool>& done, ros::atomic<bool>& failed, boost::barrier& b)
{
  b.wait();

  //ROS_INFO_STREAM("Thread " << boost::this_thread::get_id() << " starting");

  uint32_t* vals[10];
  uint64_t alloc_count = 0;
  while (!done.load())
  {
    for (uint32_t i = 0; i < 10; ++i)
    {
      vals[i] = static_cast<uint32_t*>(pool.allocate());

      if (vals[i])
      {
        ++alloc_count;
        *vals[i] = i;
      }
      else
      {
        ROS_ERROR_STREAM("Thread " << boost::this_thread::get_id() << " failed to allocate");
      }
    }

    for (uint32_t i = 0; i < 10; ++i)
    {
      if (vals[i])
      {
        if (*vals[i] != i)
        {
          ROS_ERROR_STREAM("Thread " << boost::this_thread::get_id() << " val " << vals[i] << " " << i << " = " << *vals[i]);
          failed.store(true);
        }

        pool.free(vals[i]);
      }
    }

    if (failed.load())
    {
#if FREE_LIST_DEBUG
      boost::mutex::scoped_lock lock(g_debug_mutex);
      g_debug.push_back(*pool.getDebug());
#endif
      return;
    }
  }

  //ROS_INFO_STREAM("Thread " << boost::this_thread::get_id() << " allocated " << alloc_count << " blocks");
}
开发者ID:HiroyukiMikita,项目名称:usc-clmc-ros-pkg,代码行数:51,代码来源:test_freelist.cpp


注:本文中的boost::barrier类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。