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


C++ Condition::broadcast方法代码示例

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


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

示例1: wake_all_waiters

    void wake_all_waiters(THREAD) {
      utilities::thread::Mutex::LockGuard guard(mutex_);

      if(!atomic::compare_and_swap(&should_stop_, 1, 0)) {
        // Ok, someone else has already restarted so we don't
        // have anything to do here anymore
        return;
      }

      if(cDebugThreading) {
        std::cerr << "[" << VM::current() << " WORLD waking all threads]\n";
      }

      if(state->run_state_ != ManagedThread::eAlone) {
        rubinius::bug("A non-alone thread is trying to wake all");
      }

      *check_global_interrupts_ = false;
      // For ourself..
      atomic::fetch_and_add(&pending_threads_, 1);

      waiting_to_run_.broadcast();

      state->run_state_ = ManagedThread::eRunning;
    }
开发者ID:Halfnhav,项目名称:rubinius,代码行数:25,代码来源:world_state.hpp

示例2: perform

    virtual void perform() {
      const char* thread_name = "rbx.jit";
      ManagedThread::set_current(ls_, thread_name);

      ls_->set_run_state(ManagedThread::eIndependent);

      RUBINIUS_THREAD_START(thread_name, ls_->thread_id(), 1);

#ifndef RBX_WINDOWS
      sigset_t set;
      sigfillset(&set);
      pthread_sigmask(SIG_SETMASK, &set, NULL);
#endif

      for(;;) { // forever

        BackgroundCompileRequest* req = 0;

        // Lock, wait, get a request, unlock
        {
          utilities::thread::Mutex::LockGuard guard(mutex_);

          if(pause_) {
            state = cPaused;

            paused_ = true;
            pause_condition_.broadcast();

            if(stop_) goto halt;

            while(pause_) {
              condition_.wait(mutex_);
              if(stop_) goto halt;
            }

            state = cUnknown;
            paused_ = false;
          }

          // If we've been asked to stop, do so now.
          if(stop_) goto halt;


          while(pending_requests_.empty()) {
            state = cIdle;

            // unlock and wait...
            condition_.wait(mutex_);

            if(stop_) goto halt;
          }

          // now locked again, shift a request
          req = pending_requests_.front();

          state = cRunning;
        }

        // This isn't ideal, but it's the safest. Keep the GC from
        // running while we're building the IR.
        ls_->gc_dependent();

        Context ctx(ls_);
        jit::Compiler jit(&ctx);

        // mutex now unlock, allowing others to push more requests
        //

        current_req_ = req;
        current_compiler_ = &jit;

        int spec_id = 0;
        Class* cls = req->receiver_class();
        if(cls && !cls->nil_p()) {
          spec_id = cls->class_id();
        }

        void* func = 0;
        {
          timer::Running<1000000> timer(ls_->shared().stats.jit_time_spent);

          jit.compile(req);

          func = jit.generate_function();
        }

        // We were unable to compile this function, likely
        // because it's got something we don't support.
        if(!func) {
          if(ls_->config().jit_show_compiling) {
            CompiledCode* code = req->method();
            llvm::outs() << "[[[ JIT error background compiling "
                      << ls_->enclosure_name(code) << "#" << ls_->symbol_debug_str(code->name())
                      << (req->is_block() ? " (block)" : " (method)")
                      << " ]]]\n";
          }
          // If someone was waiting on this, wake them up.
          if(utilities::thread::Condition* cond = req->waiter()) {
            cond->signal();
          }
//.........这里部分代码省略.........
开发者ID:dziulius,项目名称:rubinius,代码行数:101,代码来源:state.cpp

示例3: unlock

 void unlock() {
   stop_ = false;
   wait_condition_.broadcast();
   lock_.unlock();
 }
开发者ID:clockmaker002,项目名称:rubinius,代码行数:5,代码来源:thread_nexus.hpp


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