• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: process

void my_search::process(int proc_num){
	vector<int> cur_ch;
	vector<int> words;
	int i=0,word_size;
	while(argv[proc_num+1][i]!=0)i++;
	word_size=i;
	words.resize(argc-4);
	cur_ch.resize(argc-4);
	while(counter_file<max_file){
		boost::lock_guard<boost::mutex> lock(m);
		while((counter==0)||(thr[proc_num]==false)){
			if(counter_file>=max_file)return;
			cv.wait(m);
		}
		pantheios::log_NOTICE(PSTR("Reading thread id: ["), pantheios::threadId, PSTR("]"));
		 for(unsigned int c=0;c<memblock.size();c++){
			 char i=memblock[c];
			if(argv[proc_num+1][cur_ch[file_num]]==i)
				cur_ch[file_num]++;
			else cur_ch[file_num]=0;
			if(cur_ch[file_num]==word_size){
				words[file_num]++;sum++;cur_ch[file_num]=0;
			}
		}
		counter--;
		thr[proc_num]=false;
		if(comp_size[file_num]==0){
			cout<<argv[file_num+4]<<" "<<argv[proc_num+1]<<
					" "<<words[file_num]<<endl;
			counter_file++;
		}
		cv.notify_all();
	}
	return;
}
开发者ID:TimurKukharskiy,项目名称:Concurrency,代码行数:35,代码来源:main.cpp


示例2: main

int main()
{
  {
    L1 lk(m0);
    boost::thread t(f);
    BOOST_TEST(test1 == 0);
    while (test1 == 0)
      cv.wait(lk);
    BOOST_TEST(test1 != 0);
    test2 = 1;
    lk.unlock();
    cv.notify_one();
    t.join();
  }
  test1 = 0;
  test2 = 0;
  {
    L1 lk(m0);
    boost::thread t(f);
    BOOST_TEST(test1 == 0);
    while (test1 == 0)
      cv.wait(lk);
    BOOST_TEST(test1 != 0);
    lk.unlock();
    t.join();
  }

  return boost::report_errors();
}
开发者ID:,项目名称:,代码行数:29,代码来源:


示例3: myUserHandler15

void myUserHandler15( const CanMsgStruct/*&*/ message) {
	_canmodule_slowDown( 15 );
	boost::unique_lock<boost::mutex> lock{reception_mtx15};
	_connection_v[ 15 ].reception.newArrived = true;
	_connection_v[ 15 ].reception.receivedMessageBuffer = message;
	reception_cond15.notify_all();
}
开发者ID:quasar-team,项目名称:CanModule,代码行数:7,代码来源:canmodule_wrapper.cpp


示例4: wait_for_event

	// イベントが来るまで待つ。(最大1秒)
	bool wait_for_event() {
	  scoped_lock lk(guard_);
	  // 現在の1秒後の時間を計算
	  boost::xtime xt;
	  boost::xtime_get(&xt, boost::TIME_UTC);
	  xt.sec += 1;
	  return wakeup_.timed_wait(lk, xt);
	}
开发者ID:venkatarajasekhar,项目名称:ssa,代码行数:9,代码来源:event.hpp


示例5: put

 void put(int x)
 {
     {
         boost::mutex::scoped_lock lock(mu);
         while (is_full())
         {
             {
                 boost::mutex::scoped_lock lock(io_mu);
                 cout << "full waiting..." << endl;
             }
             cond_put.wait(mu);
         }
         stk.push(x);
         ++un_read;
     }
     cond_get.notify_one();
 }
开发者ID:opensvn,项目名称:boost_learning,代码行数:17,代码来源:condition.cpp


示例6: get

 void get(int *x)
 {
     {
         boost::mutex::scoped_lock lock(mu);
         while (is_empty())
         {
             {
                 boost::mutex::scoped_lock lock(io_mu);
                 cout << "empty waiting..." << endl;
             }
             cond_get.wait(mu);
         }
         --un_read;
         *x = stk.top();
         stk.pop();
     }
     cond_put.notify_one();
 }
开发者ID:opensvn,项目名称:boost_learning,代码行数:18,代码来源:condition.cpp


示例7: myUserHandler0

/**
 * The user-handlerX gets invoked each time there is a new can message on connectionX, according to HW sync.
 * We put this message into a buffer, protect it from the wait, and notify the wait that
 * the new msg can be picked up. Using boost for sync.
 *
 * this handler must be connected to the CanModule access point by this wrapper in the canmodule_init call,
 * and this is hardcoded. We can have only static mutexes and cond_vars, therefore we have to decide BEFORE
 * compile-time how many reception threads we want. While in principle we can have a big number easily, let's
 * limit the number of connections ( PC port or ip-number && CAN port ) we can have PER TASK to 16.
 * This corresponds to 16 CAN buses, using i.e. one systec16 module or 8 anagate-duos.
 *
 * The user can conveniently pick up the new message from the waitForNewMessage call which
 * blocks until new reception. Just a separate thread or whatever sequence is needed for the
 * blocking reception call, the user can implement whatever scheme she likes.
 */
void myUserHandler0( const CanMsgStruct/*&*/ message) {
	int connectionIndex = 0;
	LOG(Log::TRC) << __FUNCTION__ << " received a message [id= " << message.c_id << " data0= " << (int) message.c_data[ 0 ]
				  << "] connectionIndex= " << connectionIndex;
	_canmodule_slowDown( connectionIndex );
	{
		boost::unique_lock<boost::mutex> lock{reception_mtx0};
		_connection_v[ connectionIndex ].reception.newArrived = true;
		_connection_v[ connectionIndex ].reception.receivedMessageBuffer = message;
	}
	LOG(Log::TRC) << __FUNCTION__ << " new message copied, notify_all connectionIndex= " << connectionIndex;
	reception_cond0.notify_all();
}
开发者ID:quasar-team,项目名称:CanModule,代码行数:28,代码来源:canmodule_wrapper.cpp


示例8: f

void f()
{
    typedef boost::chrono::system_clock Clock;
    typedef boost::chrono::milliseconds milliseconds;
    L1 lk(m0);
    BOOST_TEST(test2 == 0);
    test1 = 1;
    cv.notify_one();
    Clock::time_point t0 = Clock::now();
    bool r = cv.wait_for(lk, milliseconds(250), Pred(test2));
    Clock::time_point t1 = Clock::now();
    if (runs == 0)
    {
        BOOST_TEST(t1 - t0 < milliseconds(250));
        BOOST_TEST(test2 != 0);
    }
    else
    {
        BOOST_TEST(t1 - t0 - milliseconds(250) < milliseconds(250+5));
        BOOST_TEST(test2 == 0);
    }
    ++runs;
}
开发者ID:,项目名称:,代码行数:23,代码来源:


示例9: loadfile

void my_search:: loadfile(int fl_num){
	file[fl_num].open(argv[fl_num+4], ios::in|ios::binary|ios::ate);
	if (file[fl_num].is_open())
	{
		comp_size[fl_num] = file[fl_num].tellg();
		file[fl_num].seekg (0, ios::beg);
		while(comp_size[fl_num]>0){
			boost::lock_guard<boost::mutex> lock(m);
			while(counter!=0){
				cv.wait(m);
			}
			pantheios::log_NOTICE(PSTR("Writing thread id: ["), pantheios::threadId, PSTR("]"));
			if(comp_size[fl_num]<1024){
				file[fl_num].read (mem, comp_size[fl_num]);
				memblock=mem;
				memblock.resize(comp_size[fl_num]);
				comp_size[fl_num]=0;
			}else {
				file[fl_num].read (mem, 1024);
				memblock=mem;
				memblock.resize(1024);
				comp_size[fl_num]-=1024;
			}
			counter=3;
			file_num=fl_num;
			for (int cc=0;cc<3;cc++)thr[cc]=true;
			cv.notify_all();
		}
		file[fl_num].close();
	}else {
		boost::lock_guard<boost::mutex> lock(m);
		cout << "Unable to open file "<<argv[fl_num+4]<<endl;
		counter_file+=3;
		cv.notify_all();
	}
	return;
}
开发者ID:TimurKukharskiy,项目名称:Concurrency,代码行数:37,代码来源:main.cpp


示例10: wait

 count_type wait()
 {
   all_futures_lock lk(waiters_);
   for (;;)
   {
     for (count_type i = 0; i < waiters_.size(); ++i)
     {
       if (waiters_[i].future_->is_ready(lk.locks[i]))
       {
         return waiters_[i].index;
       }
     }
     cv.wait(lk);
   }
 }
开发者ID:1234-,项目名称:passenger,代码行数:15,代码来源:wait_for_any.hpp


示例11: f

void f()
{
    L1 lk(m0);
    BOOST_TEST(test2 == 0);
    test1 = 1;
    cv.notify_one();
    Clock::time_point t0 = Clock::now();
    Clock::time_point t = t0 + milliseconds(250);
    while (test2 == 0 && cv.wait_for(lk, t - Clock::now()) == boost::cv_status::no_timeout) {}
    Clock::time_point t1 = Clock::now();
    if (runs == 0)
    {
        ns d = t1 - t0;
        BOOST_THREAD_TEST_IT(d, ns(max_diff));
        BOOST_TEST(test2 != 0);
    }
    else
    {
        ns d = t1 - t0 - ms(250);
        BOOST_THREAD_TEST_IT(d, ns(max_diff));
        BOOST_TEST(test2 == 0);
    }
    ++runs;
}
开发者ID:LocutusOfBorg,项目名称:poedit,代码行数:24,代码来源:wait_for_pass.cpp


示例12: notify_event

	void notify_event(const Ctrl& ctrl, uint32_t devnum=0) {
	  scoped_lock lock(guard_);
	  shared_ptr<event_ctrl<Ctrl> > p(new event_ctrl<Ctrl>(ctrl, devnum));
	  eventQueue_.push(p);
	  wakeup_.notify_one();
	}
开发者ID:venkatarajasekhar,项目名称:ssa,代码行数:6,代码来源:event.hpp


示例13: stop_listener

	// listenerを中断する
	void stop_listener() {
	  quit_ = true;
	  wakeup_.notify_one();
	}
开发者ID:venkatarajasekhar,项目名称:ssa,代码行数:5,代码来源:event.hpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ boost::dynamic_bitset类代码示例发布时间:2022-05-31
下一篇:
C++ boost::condition_variable类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap