您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ trylock函数代码示例

51自学网 2021-06-03 08:59:19
  C++
这篇教程C++ trylock函数代码示例写得很实用,希望能帮到您。

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

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

示例1: tick

void SC_LanguageClient::tick(){    if (trylock()) {		if (isLibraryCompiled()) {			::runLibrary(s_tick);		}		unlock();    }    flush();}
开发者ID:SpaceAppsXploration,项目名称:supercollider,代码行数:10,


示例2: trylock

	bool Conditional::isLocked()	{		try {			trylock();			leave();			return false;		} catch (const ibrcommon::MutexException&) {			return true;		}	}
开发者ID:Stefan-Schmidt,项目名称:ibrcommon,代码行数:10,


示例3: trylock

bool PIpcBuffer::trylock2(){	if (!isValid())		return false;	PIpcBufferHeader* h = (PIpcBufferHeader*) m_data;	pthread_mutex_t* mutex2 = &h->mutex2;	return trylock(mutex2, m_lockCount2);}
开发者ID:ctbrowser,项目名称:luna-sysmgr-ipc,代码行数:10,


示例4: mb

inlinevoidConsumer::consume(unsigned D){  /**   * This is the equivalent of do_send(must_send = 1)   */  m_force_send = 1;  do  {    if (trylock(&m_send_lock) != 0)    {      /* Other thread will send for us as we set m_force_send. */      return;    }    /**     * Now clear the flag, and start sending all data available to this node.     *     * Put a memory barrier here, so that if another thread tries to grab     * the send lock but fails due to us holding it here, we either     * 1) Will see m_force_send[nodeId] set to 1 at the end of the loop, or     * 2) We clear here the flag just set by the other thread, but then we     * will (thanks to mb()) be able to see and send all of the data already     * in the first send iteration.     */    m_force_send = 0;    mb();    /**     * This is the equivalent of link_thread_send_buffers     */    for (unsigned i = 0; i < cnt_threads; i++)    {      val[i] = rep.t[i].t.p.val[D];    }    /**     * Do a syscall...which could have affect on barriers...etc     */    if (DO_SYSCALL)    {      NdbTick_getCurrentTicks();    }    unlock(&m_send_lock);#if BUGGY_VERSION#else    mb();#endif  }  while (m_force_send != 0);}
开发者ID:ForcerKing,项目名称:ShaoqunXu-mysql5.7,代码行数:55,


示例5: while

void Thread::run(){  // The idea here is that if another thread locks this thread, that this loop  // should terminate, thus terminating the execution of this thread.  while(trylock())  {    m_runner->run();    sleep(1);    unlock();  }}
开发者ID:mickelfeng,项目名称:qt-threads,代码行数:11,


示例6: tx

// Called by RT control loop to send oob datavoid EthercatOobCom::tx(){  if (!trylock(__LINE__))    return;  if (state_ == READY_TO_SEND) {    // Packet is in need of being sent    assert(frame_!=NULL);    handle_ = ni_->tx(frame_, ni_);    state_ = WAITING_TO_RECV;    pthread_cond_signal(&busy_cond_);  }   unlock(__LINE__);  }
开发者ID:PR2,项目名称:pr2_ethercat_drivers,代码行数:16,


示例7: trylock

/* Convenience method */Mutex::TRY_LOCK_STATUS_TMutex::trylock ( const char * theErrorLocation ){    Mutex::TRY_LOCK_STATUS_T returnValue = trylock();    if ( returnValue == Mutex::FAILURE )    {        if ( theErrorLocation == (const char *) NULL )            theErrorLocation = "";        FLUSHALL();        cerr << "[" << theErrorLocation << "]  Error:  "             << "Problems while trylock()'ing mutex." << endl;    }    return returnValue;}
开发者ID:makamuy,项目名称:frob,代码行数:18,


示例8: trylock

//----------------------------------------------------------------------------// only allow one thread to execute any of these methods at a time//----------------------------------------------------------------------------inline int boost::stm::transaction::dir_tx_conflicting_lock_pthread_trylock_mutex(Mutex *mutex){   //--------------------------------------------------------------------------   throw "might not be possible to implement trylock for this";   bool txIsIrrevocable = false;   int val = trylock(mutex);   if (0 != val) return val;   lock(&latmMutex_);   if (transaction* t = get_inflight_tx_of_same_thread(false))   {      txIsIrrevocable = true;      t->must_be_in_conflicting_lock_set(mutex);      t->make_irrevocable();      t->add_to_obtained_locks(mutex);    }   try    {       //-----------------------------------------------------------------------      // if !core done, since trylock, we cannot stall & retry - just exit      //-----------------------------------------------------------------------      if (!dir_do_core_tx_conflicting_lock_pthread_lock_mutex(mutex, 0, 0, txIsIrrevocable))       {         unlock(mutex);         unlock(&latmMutex_);         return -1;      }   }   catch (...)   {      unlock(mutex);      unlock(&latmMutex_);      throw;   }   latmLockedLocksOfThreadMap_[mutex] = THREAD_ID;   unlock(&latmMutex_);   // note: we do not release the transactionsInFlightMutex - this will prevents    // new transactions from starting until this lock is released   return 0;}
开发者ID:joker-eph,项目名称:TBoost.STM,代码行数:49,


示例9: timedlock

  bool timedlock(int64_t milliseconds) const {#if defined(_POSIX_TIMEOUTS) && _POSIX_TIMEOUTS >= 200112L    PROFILE_MUTEX_START_LOCK();    struct timespec ts;    Util::toTimespec(ts, milliseconds);    int ret = pthread_mutex_timedlock(&pthread_mutex_, &ts);    if (ret == 0) {      PROFILE_MUTEX_LOCKED();      return true;    }    PROFILE_MUTEX_NOT_LOCKED();    return false;#else    // If pthread_mutex_timedlock isn't supported, the safest thing to do    // is just do a nonblocking trylock.    return trylock();#endif  }
开发者ID:caocf,项目名称:workspace-kepler,代码行数:20,


示例10: unlock

/* THREAD: RT */intEngine::process ( nframes_t nframes ){    /* FIXME: wrong place for this */    _thread.set( "RT" );    if ( ! trylock() )    {        /* the data structures we need to access here (tracks and         * their ports, but not track contents) may be in an         * inconsistent state at the moment. Just punt and drop this         * buffer. */        ++_buffers_dropped;        return 0;    }    _process_callback(nframes, _process_callback_user_data);    unlock();    return 0;}
开发者ID:elthariel,项目名称:non-daw,代码行数:23,


示例11: switch

BOOLEANMutex::isLocked(){    Mutex::TRY_LOCK_STATUS_T  tryLockStatus;    switch ( tryLockStatus = trylock() )    {    case Mutex::SUCCESS:        /* We just locked ourself.  If unlock fails... *         * Well, we are locked...  And probably hosed. */        switch ( unlock() )        {        case ::SUCCESS:            return FALSE;        /* If this happens, something truly odd is going on... */        case ::FAILURE:        default:            FLUSHALL();            cerr << "[Mutex:isLocked]  Internal Failure:  "                 << "trylock() returned SUCCESS.   unlock() returned FAILURE.  "                 << "(So we've just locked the mutex.)" << endl;            return TRUE;        }    case Mutex::FAILURE:        return FALSE;    case Mutex::ALREADY_LOCKED:        return TRUE;    default:        FLUSHALL();        cerr << "[Mutex:isLocked]  Impossible Error: tryLock() returned: "             << int4(tryLockStatus) << ".  Assuming we are locked..." << endl;        return TRUE; /* Worst case scenario: Assume we are locked. */    }}
开发者ID:makamuy,项目名称:frob,代码行数:37,


示例12: pipe_read

static int pipe_read(struct mill_pipe_s *mp, void *ptr) {    unsigned size = mp->sz;    int n, total = 0;    while (1) {        if (trylock(mp)) {again:            n = (int) read(mp->fd[0], (char *) ptr + total, size - total);            if (mill_slow(n == 0)) {                /* done */                mill_assert(total == 0);                unlock(mp);                return 0;            }            if (n > 0) {                total += n;                if (mill_fast(total == size)) {                    unlock(mp);                    return total;                }                goto again;            }            /* n == -1 */            if (errno == EINTR)                goto again;            if (errno == EAGAIN) {                mill_fdevent(mp->fd[0], FDW_IN, -1);                goto again;            }            unlock(mp);            break;        }        mill_fdevent(mp->fd[0], FDW_IN, -1);        /* Multiple threads may receive notification. Race for the lock. */    }    return -1;}
开发者ID:johneh,项目名称:libmill_worker,代码行数:37,


示例13: trylock1

static int trylock1() {	return trylock(std::multimap<std::wstring, unsigned long long int>());}
开发者ID:EarlOfWenc,项目名称:mumble,代码行数:3,


示例14: lock

void lock(struct lock* m) {#if SYNC	task_loop(trylock(m) == -1);#endif}
开发者ID:WareX97,项目名称:K2,代码行数:5,



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


C++ trylock_page函数代码示例
C++ try_val_to_str函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。