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


C++ condition::wait方法代码示例

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


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

示例1: output_

  void output_(FILE* f)
  {
    IO_TYPE ioStream(f,"w");

    uint64_t count = 0;
    uint64_t nextStart = 0;
    while (count< count_)
    {
      boost::mutex::scoped_lock lock(out_buf_mtx_);
      while (out_buf_size_ == 0)
        out_buf_con_.wait(lock);

      IASSERT(fwrite(&out_buf_size_, sizeof(uint32_t), 1, f)==1);
      IASSERT(fwrite(&out_buf_num_, sizeof(uint32_t), 1, f)==1);
      //IASSERT(fwrite(&max_record_len_of_this_run_, sizeof(uint32_t), 1, f)==1);	  //TODO
      uint64_t nextStartPos = ftell(f);
      IASSERT(fwrite(&nextStart, sizeof(uint64_t), 1, f)==1);
      //IASSERT(fwrite(out_buf_, out_buf_size_, 1, f)==1);
      ioStream.write(out_buf_, out_buf_size_);
      nextStart = ftell(f);
      fseek(f, nextStartPos, SEEK_SET);
      IASSERT(fwrite(&nextStart, sizeof(uint64_t), 1, f)==1);
      fseek(f, nextStart, SEEK_SET);

      IASSERT(t_check_sort_());
      count += out_buf_num_;
      out_buf_size_ = out_buf_num_ = 0;
      out_buf_con_.notify_one();
    }

    std::cout<<"Outputting is over...\n";
  }
开发者ID:RedSunCMX,项目名称:izenelib,代码行数:32,代码来源:sort_runner.hpp

示例2: player

void player(int active)
{
    boost::unique_lock<boost::mutex> lock(mutex);

    int other = active == PLAYER_A ? PLAYER_B : PLAYER_A;

    while (state < GAME_OVER)
    {
        //std::cout << player_name(active) << ": Play." << std::endl;
        state = other;
        cond.notify_all();
        do
        {
            cond.wait(lock);
            if (state == other)
            {
                std::cout << "---" << player_name(active)
                          << ": Spurious wakeup!" << std::endl;
            }
        } while (state == other);
    }

    ++state;
    std::cout << player_name(active) << ": Gone." << std::endl;
    cond.notify_all();
}
开发者ID:Cabriter,项目名称:abelkhan,代码行数:26,代码来源:tennis.cpp

示例3: run

        virtual bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {

            if (txn->lockState()->isLocked()) {
                errmsg = "fsync: Cannot execute fsync command from contexts that hold a data lock";
                return false;
            }

            bool sync = !cmdObj["async"].trueValue(); // async means do an fsync, but return immediately
            bool lock = cmdObj["lock"].trueValue();
            log() << "CMD fsync: sync:" << sync << " lock:" << lock << endl;
            if( lock ) {
                if ( ! sync ) {
                    errmsg = "fsync: sync option must be true when using lock";
                    return false;
                }

                SimpleMutex::scoped_lock lk(m);
                err = "";
                
                (new FSyncLockThread())->go();
                while ( ! locked && err.size() == 0 ) {
                    _threadSync.wait( m );
                }
                
                if ( err.size() ){
                    errmsg = err;
                    return false;
                }
                
                log() << "db is now locked, no writes allowed. db.fsyncUnlock() to unlock" << endl;
                log() << "    For more info see " << FSyncCommand::url() << endl;
                result.append("info", "now locked against writes, use db.fsyncUnlock() to unlock");
                result.append("seeAlso", FSyncCommand::url());

            }
            else {
                // the simple fsync command case
                if (sync) {
                    // can this be GlobalRead? and if it can, it should be nongreedy.
                    ScopedTransaction transaction(txn, MODE_X);
                    Lock::GlobalWrite w(txn->lockState());
                    getDur().commitNow(txn);

                    //  No WriteUnitOfWork needed, as this does no writes of its own.
                }

                // Take a global IS lock to ensure the storage engine is not shutdown
                Lock::GlobalLock global(txn->lockState(), MODE_IS, UINT_MAX);
                StorageEngine* storageEngine = getGlobalServiceContext()->getGlobalStorageEngine();
                result.append( "numFiles" , storageEngine->flushAllFiles( sync ) );
            }
            return 1;
        }
开发者ID:lalford,项目名称:mongo,代码行数:53,代码来源:fsync.cpp

示例4: lock

void
interpreter_lock_impl::unlock_thread() {
	boost::mutex::scoped_lock lock(mutex_);
	while (thread_lock_count_ > 0) {
		condition_.wait(lock);
	}
	assert(NULL != thread_state_);
	PyEval_RestoreThread(thread_state_);
	thread_lock_count_ = -1;
	thread_state_ = NULL;
	condition_.notify_all();
}
开发者ID:Leonya,项目名称:xiva,代码行数:12,代码来源:interpreter_lock.cpp

示例5: acquire_write_lock

    // this function is currently not exception-safe:
    // if the wait calls throw, m_pendingWriter can be left in an inconsistent 
    // state
    void acquire_write_lock()
    {
        boost::mutex::scoped_lock lock(mtx);

        // ensure subsequent readers block
        ++num_pending_writers;
        
        // ensure all reader locks are released
        while(num_readers > 0)
        {
            no_readers.wait(lock);
        }

        // only continue when the current writer has finished 
        // and another writer has not been woken first
        while(is_current_writer)
        {
            writer_finished.wait(lock);
        }
        --num_pending_writers;
        is_current_writer = true;
    }
开发者ID:fullstackenviormentss,项目名称:sbmt,代码行数:25,代码来源:read_write_mutex.hpp

示例6: acquire_read_lock

    void acquire_read_lock()
    {
        boost::mutex::scoped_lock lock(mtx);

        // require a while loop here, since when the writerFinished condition is
        // notified, we should not allow readers to lock if there is a writer 
        // waiting.  if there is a writer waiting, we continue waiting
        while(num_pending_writers != 0 || is_current_writer)
        {
            writer_finished.wait(lock);
        }
        ++num_readers;
    }
开发者ID:fullstackenviormentss,项目名称:sbmt,代码行数:13,代码来源:read_write_mutex.hpp

示例7: runtime_error

void
interpreter_lock_impl::lock() {
	boost::mutex::scoped_lock lock(mutex_);
	while (NULL != thread_state_) {
		if (!thread_lock_count_) {
			break;
		}
		condition_.wait(lock);
	}
	if (NULL == thread_state_) {
		throw std::runtime_error("Can not acquire python interpreter lock");
	}
	PyEval_RestoreThread(thread_state_);
	thread_lock_count_++;
}
开发者ID:Leonya,项目名称:xiva,代码行数:15,代码来源:interpreter_lock.cpp

示例8: run

        virtual bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {

            if (txn->lockState()->isLocked()) {
                errmsg = "fsync: Cannot execute fsync command from contexts that hold a data lock";
                return false;
            }

            bool sync = !cmdObj["async"].trueValue(); // async means do an fsync, but return immediately
            bool lock = cmdObj["lock"].trueValue();
            log() << "CMD fsync: sync:" << sync << " lock:" << lock << endl;
            if( lock ) {
                if ( ! sync ) {
                    errmsg = "fsync: sync option must be true when using lock";
                    return false;
                }

                SimpleMutex::scoped_lock lk(m);
                err = "";
                
                (new FSyncLockThread())->go();
                while ( ! locked && err.size() == 0 ) {
                    _threadSync.wait( m );
                }
                
                if ( err.size() ){
                    errmsg = err;
                    return false;
                }
                
                log() << "db is now locked for snapshotting, no writes allowed. db.fsyncUnlock() to unlock" << endl;
                log() << "    For more info see " << FSyncCommand::url() << endl;
                result.append("info", "now locked against writes, use db.fsyncUnlock() to unlock");
                result.append("seeAlso", FSyncCommand::url());

            }
            else {
                // the simple fsync command case
                if (sync) {
                    // can this be GlobalRead? and if it can, it should be nongreedy.
                    Lock::GlobalWrite w(txn->lockState());
                    getDur().commitNow();
                }
                // question : is it ok this is not in the dblock? i think so but this is a change from past behavior, 
                // please advise.
                result.append( "numFiles" , MemoryMappedFile::flushAll( sync ) );
            }
            return 1;
        }
开发者ID:Robbie1977,项目名称:mongo,代码行数:48,代码来源:fsync.cpp

示例9: waitForShutdown

int WServer::waitForShutdown(const char *restartWatchFile)
{
#if !defined(WIN32)
  if (!CatchSignals) {
    for(;;)
      sleep(0x1<<16);
  }
#endif // WIN32

#ifdef WT_THREADED

#if !defined(_WIN32)
  sigset_t wait_mask;
  sigemptyset(&wait_mask);

  sigaddset(&wait_mask, SIGHUP);
  sigaddset(&wait_mask, SIGINT);
  sigaddset(&wait_mask, SIGQUIT);
  sigaddset(&wait_mask, SIGTERM);
  pthread_sigmask(SIG_BLOCK, &wait_mask, 0);

  for (;;) {
    int sig;
    sigwait(&wait_mask, &sig);

    if (sig != -1) {
      if (sig == SIGHUP) {
	if (instance())
	  instance()->configuration().rereadConfiguration();
      } else
	return sig;
    }
  }

#else  // WIN32

  boost::mutex::scoped_lock terminationLock(terminationMutex);
  SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
  while (!terminationRequested)
    terminationCondition.wait(terminationLock);
  SetConsoleCtrlHandler(console_ctrl_handler, FALSE);
  return 0;

#endif // WIN32
#else
  return 0;
#endif // WT_THREADED
}
开发者ID:bvanhauwaert,项目名称:wt,代码行数:48,代码来源:WServer.C

示例10: yield

    void yield(result_ref_t result) // in the same thread as 'work()'.
    {
        boost::mutex::scoped_lock lock(m_mutex);

        // 'result' is alive until next increment,
        // as far as 'value' can go across thread-boundary.
        m_presult = boost::addressof(result);
        m_status.reset(block_incrementing::value);
        m_cond.notify_one();

        while (!m_status.test(block_incrementing::value) && !m_status.test(block_interrupted::value))
            m_cond.wait(lock);

        if (m_status.test(block_interrupted::value))
            throw yield_break_exception();
    }
开发者ID:fpelliccioni,项目名称:pstade,代码行数:16,代码来源:block_iterator_impl.hpp

示例11: run

        virtual bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {

            if (Lock::isLocked()) {
                errmsg = "fsync: Cannot execute fsync command from contexts that hold a data lock";
                return false;
            }

            bool sync = !cmdObj["async"].trueValue(); // async means do an fsync, but return immediately
            bool lock = cmdObj["lock"].trueValue();
            if( lock ) {
                if ( ! sync ) {
                    errmsg = "fsync: sync option must be true when using lock";
                    return false;
                }

                SimpleMutex::scoped_lock lk(m);
                err = "";
                
                (new FSyncLockThread())->go();
                while ( ! locked && err.size() == 0 ) {
                    _threadSync.wait( m );
                }
                
                if ( err.size() ){
                    errmsg = err;
                    return false;
                }
                
                log() << "db is now locked for snapshotting, no writes allowed. db.fsyncUnlock() to unlock" << endl;
                log() << "    For more info see " << FSyncCommand::url() << endl;
                result.append("info", "now locked against writes, use db.fsyncUnlock() to unlock");
                result.append("seeAlso", FSyncCommand::url());

            }
            else {
                // the simple fsync command case
                if (sync) {
                    Lock::GlobalWrite w; // can this be GlobalRead? and if it can, it should be nongreedy.
                    DEV LOG(0) << "in fsync: flushAll/commitNow not implemented, doing nothing!" << endl;
                }
                // question : is it ok this is not in the dblock? i think so but this is a change from past behavior, 
                // please advise.
                DEV LOG(0) << "in fsync: number of files flushed not known, arbitrarily reporting 1!" << endl;
                result.append( "numFiles" , 1 );
            }
            return 1;
        }
开发者ID:aberg001,项目名称:mongo,代码行数:47,代码来源:fsync.cpp

示例12: main

int main(int argc, char* argv[])
{

	boost::mutex::scoped_lock lock(g_close_mutex);

	io_service ios;
	boost::shared_ptr<player> player_sptr = player::create(ios);

	std::string ipport = "127.0.0.1:9906";
	player_sptr->start(endpoint_from_string<endpoint>(ipport));
	
	ios.run();

	g_close_condition.wait(lock);

	return 0;
}
开发者ID:guangzhuwu,项目名称:p2streaming,代码行数:17,代码来源:test_player.cpp

示例13: pop

    //
    //  blocking pop:  return a TPtr if available
    //
    T pop()
    {
        boost::mutex::scoped_lock data_available_lock(data_available_mtx);

        while(!data_available)
            data_available_cond.wait(data_available_lock);

        T p;
        {
            boost::mutex::scoped_lock lock(q_mutex);
            assert(q_.size() > 0);
            p = q_.back();
            q_.pop();
            data_available = q_.size() > 0;
        }

        return p;
    };
开发者ID:straszheim,项目名称:mephitis,代码行数:21,代码来源:concurrent_queue.hpp

示例14: dequeue

    bool dequeue( msg_type & msg)
    {
      typename boost::mutex::scoped_lock lock( mtx_);
      if ( active_ == false && empty_() ) return false;
      while (empty_() ){
	not_empty_cond_.wait( 
			     lock,
			     boost::bind(
					 & Queue< T, Q >::consumers_activate_,
					 this) );
      }
      dequeue_( msg);
      if ( active_ == true && queue_.size() <= low_water_mark_) {
	
	not_full_cond_.notify_one();
      }
      return msg ? true : false;
    }
开发者ID:maoy,项目名称:mosaic,代码行数:18,代码来源:queue.hpp

示例15: enqueue

    bool enqueue( msg_type const& msg)
    {
      typename boost::mutex::scoped_lock lock( mtx_);
      if ( active_ == false) return false;
      not_full_cond_.wait( 
			  lock,
			  boost::bind(
				      & Queue< T, Q >::suppliers_activate_,
				      this) );
      if ( active_ != false)
	{
	  enqueue_( msg);
	  not_empty_cond_.notify_one();
	  return true;
	}
      else
	return false;
    }
开发者ID:maoy,项目名称:mosaic,代码行数:18,代码来源:queue.hpp


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