本文整理汇总了C++中boost::barrier::wait方法的典型用法代码示例。如果您正苦于以下问题:C++ barrier::wait方法的具体用法?C++ barrier::wait怎么用?C++ barrier::wait使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::barrier
的用法示例。
在下文中一共展示了barrier::wait方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
static void TestThread2(TSArray<int> *ap)
{
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
cout << "Thread 2 attempting to lock element 0." << endl;
ap->Lock(0); //Attempt to lock element 0; will block for 4 seconds.
cout << "Thread 2 locked element 0." << endl;
(*ap)[0] = 12;
bar.wait(); //resynchronise
cout << "Thread 2 locking element 3." << endl;
ap->Lock(3);
boost::this_thread::sleep(boost::posix_time::milliseconds(5000));
cout << "Thread 2 releasing element 3." << endl;
ap->Unlock(3);
bar.wait(); //resynchronise
//A more "real world" example in which two threads are inevitably going to interact
for(unsigned i=6;i<1000;i++)
{
ap->Lock(i);
(*ap)[i] = (*ap)[i-1] - 1;
ap->Unlock(i);
}
}
示例2: 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();
}
}
示例3: 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));
}
示例4: 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;
}
示例5: 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));
}
示例6: 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);
}
示例7: operator
void operator() ()
{
rtc_clock timer;
unsigned char tmp[chunk_size];
thread_sync->wait();
timer.reset();
timer.start();
for(unsigned long i=0;i<BUFFER_SIZE;i+=chunk_size) {
memcpy(tmp, buffer1 + i, chunk_size);
}
timer.stop();
double mbps = ((double)BUFFER_SIZE)/timer.elapsed_time();
BOOST_LOG_TRIVIAL(info) << "MEMREAD_SPEED "<< convert(mbps) << "MB/s";
timer.reset();
timer.start();
for(unsigned long i=0;i<BUFFER_SIZE;i+=chunk_size) {
memcpy(buffer1 + i, tmp, chunk_size);
}
timer.stop();
mbps = ((double)BUFFER_SIZE)/timer.elapsed_time();
BOOST_LOG_TRIVIAL(info) << "MEMWRITE_SPEED "<< convert(mbps) << "MB/s";
timer.reset();
timer.start();
for(unsigned long i=0;i<BUFFER_SIZE;i+=chunk_size) {
memcpy(buffer2 + i, buffer1 + i, chunk_size);
}
timer.stop();
mbps = ((double)BUFFER_SIZE)/timer.elapsed_time();
BOOST_LOG_TRIVIAL(info) << "MEMCPY_SPEED "<< convert(mbps) << "MB/s";
}
示例8:
~Process()
{
destroy_threads = true;
main_barrier.wait();
for(auto thread: threads) { thread->join(); }
for(auto data: threads_data) { delete(data); }
}
示例9: operator
void operator() ()
{
rtc_clock timer;
unsigned char tmp[chunk_size];
const unsigned long mask = buffer_items - 1;
thread_sync->wait();
timer.reset();
timer.start();
for(unsigned long i=0,j=0;i<buffer_items;i++) {
memcpy(tmp, buffer1 + j*chunk_size, chunk_size);
j=LCG_NEXT(j,mask);
}
timer.stop();
double mbps = ((double)buffer_items*chunk_size)/timer.elapsed_time();
BOOST_LOG_TRIVIAL(info) << "MEMREAD_SPEED "<< convert(mbps) << "MB/s";
timer.reset();
timer.start();
for(unsigned long i=0,j=0;i<buffer_items;i++) {
memcpy(buffer1 + j*chunk_size, tmp, chunk_size);
j=LCG_NEXT(j,mask);
}
timer.stop();
mbps = ((double)buffer_items*chunk_size)/timer.elapsed_time();
BOOST_LOG_TRIVIAL(info) << "MEMWRITE_SPEED "<< convert(mbps) << "MB/s";
timer.reset();
timer.start();
for(unsigned long i=0,j=0;i<buffer_items;i++) {
memcpy(buffer2 + j*chunk_size, buffer1 + j*chunk_size, chunk_size);
j=LCG_NEXT(j,mask);
}
timer.stop();
mbps = ((double)buffer_items*chunk_size)/timer.elapsed_time();
BOOST_LOG_TRIVIAL(info) << "MEMCPY_SPEED "<< convert(mbps) << "MB/s";
}
示例10: stopStreaming
void stopStreaming()
{
env->taskScheduler().triggerEvent(removeFaceSubstreamsTriggerId, NULL);
env->taskScheduler().triggerEvent(removeBinularsSubstreamTriggerId, NULL);
stopStreamingBarrier.wait();
delete shm;
}
示例11: 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;
}
示例12: invoke_n_workers
void invoke_n_workers(
boost::barrier& b
, double& elapsed
, boost::uint64_t workers
)
{
b.wait();
invoke_n_workers_nowait(elapsed, workers);
}
示例13: 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!");
}
示例14: 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();
}
示例15: 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]);
}
}
}