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


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

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


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

示例1: 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

示例2: deactivate_

    void deactivate_()
    {
      if ( active_)
	{
	  active_ = false;
	  not_empty_cond_.notify_all();
	  not_full_cond_.notify_all();
	}
    }
开发者ID:maoy,项目名称:mosaic,代码行数:9,代码来源:queue.hpp

示例3: lock

void
interpreter_lock_impl::unlock() {
	boost::mutex::scoped_lock lock(mutex_);
	assert(NULL != thread_state_);
	/* thread_state_ = */ PyEval_SaveThread();
	if (!--thread_lock_count_) {
		condition_.notify_all();
	}
}
开发者ID:Leonya,项目名称:xiva,代码行数:9,代码来源:interpreter_lock.cpp

示例4: SlotOnNewStateHandler

 void SlotOnNewStateHandler(net::ClientId client_id, net::ServerId server_id, net::ClientState client_state)
 {
     if (client_state != net::CLIENT_STATE_CONNECTED)
     {
         std::cout << "Disconnected from server." << std::endl;
         
         this->client_id_ = 0;
         finish = true;
         on_message_condition.notify_all();
     }
 }
开发者ID:codesburner,项目名称:HomeAutomation,代码行数:11,代码来源:atomic.cpp

示例5: release_read_lock

    void release_read_lock()
    {
        boost::mutex::scoped_lock lock(mtx);
        --num_readers;

        if(num_readers == 0)
        {
            // must notify_all here, since if there are multiple waiting writers
            // they should all be woken (they continue to acquire the lock 
            // exclusively though)
            no_readers.notify_all();
        }
    }
开发者ID:fullstackenviormentss,项目名称:sbmt,代码行数:13,代码来源:read_write_mutex.hpp

示例6: main

int main()
{
    state = START;

    boost::thread thrda(&player, PLAYER_A);
    boost::thread thrdb(&player, PLAYER_B);

    boost::xtime xt;
    boost::xtime_get(&xt, boost::TIME_UTC_);
    xt.sec += 1;
    boost::thread::sleep(xt);
    {
        boost::unique_lock<boost::mutex> lock(mutex);
        std::cout << "---Noise ON..." << std::endl;
    }

    for (int i = 0; i < 10; ++i)
        cond.notify_all();

    {
        boost::unique_lock<boost::mutex> lock(mutex);
        std::cout << "---Noise OFF..." << std::endl;
        state = GAME_OVER;
        cond.notify_all();
        do
        {
            cond.wait(lock);
        } while (state != BOTH_PLAYERS_GONE);
    }

    std::cout << "GAME OVER" << std::endl;

    thrda.join();
    thrdb.join();

    return 0;
}
开发者ID:Cabriter,项目名称:abelkhan,代码行数:37,代码来源:tennis.cpp

示例7: main

int main(int argc, char* argv[])
{
    state = START;

    boost::thread thrda(thread_adapter(&player, (void*)PLAYER_A));
    boost::thread thrdb(thread_adapter(&player, (void*)PLAYER_B));

    boost::xtime xt;
    boost::xtime_get(&xt, boost::TIME_UTC);
    xt.sec += 1;
    boost::thread::sleep(xt);
    {
        boost::mutex::scoped_lock lock(mutex);
        std::cout << "---Noise ON..." << std::endl;
    }

    for (int i = 0; i < 1000000; ++i)
        cond.notify_all();

    {
        boost::mutex::scoped_lock lock(mutex);
        std::cout << "---Noise OFF..." << std::endl;
        state = GAME_OVER;
        cond.notify_all();
        do
        {
            cond.wait(lock);
        } while (state != BOTH_PLAYERS_GONE);
    }

    std::cout << "GAME OVER" << std::endl;

    thrda.join();
    thrdb.join();

    return 0;
}
开发者ID:KerwinMa,项目名称:AerothFlyffSource,代码行数:37,代码来源:tennis.cpp

示例8: console_ctrl_handler

BOOL WINAPI console_ctrl_handler(DWORD ctrl_type)
{
  switch (ctrl_type)
  {
  case CTRL_C_EVENT:
  case CTRL_BREAK_EVENT:
  case CTRL_CLOSE_EVENT:
  case CTRL_SHUTDOWN_EVENT:
    {
      boost::mutex::scoped_lock terminationLock(terminationMutex);
      terminationRequested = true;
      terminationCondition.notify_all(); // should be just 1
      return TRUE;
    }
  default:
    return FALSE;
  }
}
开发者ID:bvanhauwaert,项目名称:wt,代码行数:18,代码来源:WServer.C

示例9: release_write_lock

 void release_write_lock()
 {        
     boost::mutex::scoped_lock lock(mtx);
     is_current_writer = false;
     writer_finished.notify_all();
 }
开发者ID:fullstackenviormentss,项目名称:sbmt,代码行数:6,代码来源:read_write_mutex.hpp

示例10: SlotOnNewDataHandler

    void SlotOnNewDataHandler(net::ClientId client_id, net::ServerId server_id, common::Byteset data)
    {
        for (unsigned int n = 0; n < data.GetSize(); n++)
        {
            this->buffer_.push_back(data[n]);
        }

        while (this->buffer_.size() >= 8)
        {
            std::string command = "";
            command += (char)this->buffer_[0];
            command += (char)this->buffer_[1];
            command += (char)this->buffer_[2];
            command += (char)this->buffer_[3];

            std::string payload_length_str = "";
            payload_length_str += (char)this->buffer_[4];
            payload_length_str += (char)this->buffer_[5];
            payload_length_str += (char)this->buffer_[6];
            payload_length_str += (char)this->buffer_[7];
            
            unsigned int payload_length = boost::lexical_cast<unsigned int>(payload_length_str);
            
            if (this->buffer_.size() - 8 < payload_length)
            {
                return;
            }
         
            std::string payload = "";
            for (unsigned int n = 8; n < payload_length + 8; n++)
            {
                payload += (char)this->buffer_[n];
            }
            
            this->buffer_.erase(this->buffer_.begin(), this->buffer_.begin() + payload_length + 8);
            
            if (command == "TEXT")
            {
                std::cout << payload << std::flush;
            }
            else if (command == "PROM")
            {
                this->prompt_ = payload;
                on_message_condition.notify_all();
            }
            else if (command == "COMP")
            {
                autocomplete_list.clear();
                
                if (payload.length() > 0)
                {
                    boost::algorithm::split(autocomplete_list, payload, boost::is_any_of("\n"), boost::algorithm::token_compress_on);
                }
                
                on_message_condition.notify_all();
            }
            else
            {
                std::cerr << "Could not parse package." << std::endl;
                finish = true;
                on_message_condition.notify_all();
                break;
            }
        }
    }
开发者ID:codesburner,项目名称:HomeAutomation,代码行数:65,代码来源:atomic.cpp

示例11: terminate

void WServer::terminate()
{
    boost::mutex::scoped_lock terminationLock(terminationMutex);
    terminationRequested = true;
    terminationCondition.notify_all(); // should be just 1
}
开发者ID:mickythump,项目名称:wt,代码行数:6,代码来源:WServer.C

示例12:

inline void
boost_threaded_monitor::notify_all() {
	cond_.notify_all();
}
开发者ID:Tigro,项目名称:elliptics-fastcgi,代码行数:4,代码来源:boost_threaded.hpp


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