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


C++ ThreadInfo::signal方法代码示例

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


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

示例1: shutDown

void ThreadPool::shutDown() {
    Lock(poolLock);
    ThreadInfo *p;
    // note: do not terminate thread 0 (main thread) in this loop
    for (unsigned i = 1; i < nThreads; i++) {
        p = data[i];
        // All threads should be idle when this function is called.
        if (p->state == ThreadInfo::Idle) {
          // Set the thread to the terminating state that will force thread
          // procedure exit
          p->state = ThreadInfo::Terminating;
          // unblock the thread
          p->signal();
       }
       // wait for the thread to terminate
#ifdef _WIN32
       WaitForSingleObject(p->thread_id,INFINITE);
#else
       void *value_ptr;
       pthread_join(p->thread_id,&value_ptr);
#endif
       // Free thread data 
       delete p;
    }
    // now free main thread data
    delete data[0]->work;
    delete data[0]; // main thread structure
    Unlock(poolLock);
}
开发者ID:,项目名称:,代码行数:29,代码来源:

示例2: resize

void ThreadPool::resize(unsigned n, SearchController *controller) {
    if (n >= 1 && n < Constants::MaxCPUs && n != nThreads) {
        lock();
#ifdef NUMA
        topo.recalc();
#endif
        if (n>nThreads) {
            // growing
            while (n > nThreads) {
               data[nThreads] = new ThreadInfo(this,nThreads);
               nThreads++;
            }
        }
        else {
            // shrinking
            while (n < nThreads) {
                ThreadInfo *p = data[nThreads-1];
                p->state = ThreadInfo::Terminating;
                if (p->state == ThreadInfo::Idle) {
                    p->signal(); // unblock thread & exit thread proc
                    // wait for thread exit
#ifdef _WIN32
                    WaitForSingleObject(p->thread_id,INFINITE);
#else
                    void *value_ptr;
                    pthread_join(p->thread_id,&value_ptr);
#endif
                }
                delete p;
                data[nThreads] = NULL;
                --nThreads;
            }
        }
        unlock();
    }
    ASSERT(nThreads == n);
    availableMask = (n == 64) ? 0xffffffffffffffffULL :
       (1ULL << n)-1;
}
开发者ID:,项目名称:,代码行数:39,代码来源:

示例3: checkIn

void ThreadPool::checkIn(ThreadInfo *ti) {
#ifdef _THREAD_TRACE
    {
        std::ostringstream s;
        s << "checkIn: " << ti->index << " master=" <<
            ti->work->split->master->index << '\0';
        log(s.str());
    }
#endif
    Lock(poolLock);
    SplitPoint *split = ti->work->split;
    ThreadInfo *parent = split->master;
    Search *parentSearch = parent->work;
    // lock parent's stack
    Lock(parentSearch->splitLock);
    split->lock();
    // dissociate the thread from the parent
    ArasanSet<ThreadInfo *,Constants::MaxCPUs> &slaves =
        split->slaves;
    // remove ti from the list of slave threads in the parent
#ifdef _THREAD_TRACE
    {
        std::ostringstream s;
        s << "removing slave thread " <<  ti->index << " from master "
          << split->master->index << '\0';
        log(s.str());
    }
#endif
#ifdef _DEBUG
    ASSERT(slaves.remove(ti));
#else
    slaves.remove(ti);
#endif
    const int remaining = slaves.size();
    const bool top = split - parentSearch->splitStack + 1 == parentSearch->activeSplitPoints;
#ifdef _THREAD_TRACE
    {
        std::ostringstream s;
        s << "after checkIn: " << ti->index << " remaining: " << remaining << " top=" << top << '\0';
        log(s.str());
    }
#endif
    if (!remaining && top) {
        // all slave threads are completed, so signal parent that it
        // can exit its wait state and pop the split stack.
        ASSERT(parent);
        // Set parent state to Working before it even wakes up. This
        // ensures it will not be allocated to another split point.
        parent->state = ThreadInfo::Working;
        activeMask |= (1ULL << parent->index);
#ifdef _THREAD_TRACE
        std::ostringstream s;
        s << "thread " << ti->index <<  
            " signaling parent (" << parent->index << ")" << 
            " parent state=" << parent->state << '\0';
        log(s.str());
#endif
        ASSERT(parent->index != ti->index);
#ifdef _THREAD_TRACE
        log("signal",parent->index);
#endif
        parent->signal();
    }
    // ensure we we will wait when back in the idle loop
    ti->reset();
    split->unlock();
    Unlock(parentSearch->splitLock);
    Unlock(poolLock);
}
开发者ID:,项目名称:,代码行数:69,代码来源:


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