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


C++ ThreadException函数代码示例

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


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

示例1: Debug

void Thread::start()
{
  Debug( 1, "Starting thread" );
  if ( isThread() )
    throw ThreadException( "Can't self start thread" );
  mThreadMutex.lock();
  if ( !mStarted )
  {
    pthread_attr_t threadAttrs;
    pthread_attr_init( &threadAttrs );
    pthread_attr_setscope( &threadAttrs, PTHREAD_SCOPE_SYSTEM );

    mStarted = true;
    if ( pthread_create( &mThread, &threadAttrs, mThreadFunc, this ) < 0 )
      throw ThreadException( stringtf( "Can't create thread: %s", strerror(errno) ) );
    pthread_attr_destroy( &threadAttrs );
  }
  else
  {
    Error( "Attempt to start already running thread %d", mPid );
  }
  mThreadCondition.wait();
  mThreadMutex.unlock();
  Debug( 1, "Started thread %d", mPid );
}
开发者ID:AaronJorgensen,项目名称:ZoneMinder,代码行数:25,代码来源:zm_thread.cpp

示例2: start

	virtual void
	start(Runnable *runnable, bool detached, bool runnableShouldBeFreed) throw(ThreadException) {
		this->runnable = runnable;
		this->detached = detached;
		this->runnableShouldBeFreed = runnableShouldBeFreed;
		if (detached) {
			pthread_attr_t attr;

			if (pthread_attr_init(&attr) != 0) {
				throw ThreadException("Cannot initialize pthread attribute.");
			}
			if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0) {
				throw ThreadException("Cannot set pthread detach state.");
			}
			ref();
			if (pthread_create(&thread, &attr, entry, this) != 0) {
				unref();
				throw ThreadException("Cannot create a thread.");
			}
			pthread_attr_destroy(&attr);
		} else {
			ref();
			if (pthread_create(&thread, NULL, entry, this) != 0) {
				unref();
				throw ThreadException("Cannot create a thread.");
			}
		}
	}
开发者ID:NonPlayerCharactor,项目名称:cn-rag-client,代码行数:28,代码来源:Thread.cpp

示例3: _threadbase

	/*! Ctor.
	  \param detach detach thread if true
	  \param stacksize default thread stacksize */
	_threadbase(const bool detach, const size_t stacksize) throw(ThreadException) : _attr(), _tid(), _exitval()
	{
		if (pthread_attr_init(&_attr))
			throw ThreadException("pthread_attr_init failure");
		if (stacksize && pthread_attr_setstacksize(&_attr, stacksize))
			throw ThreadException("pthread_attr_setstacksize failure");
		if (detach && pthread_attr_setdetachstate(&_attr, PTHREAD_CREATE_DETACHED))
			throw ThreadException("pthread_attr_setdetachstate failure");
	}
开发者ID:capitalk,项目名称:fix8,代码行数:12,代码来源:thread.hpp

示例4: m_runnable

 Thread::Thread(IRunnable& runnable, bool detach) :
   m_runnable(runnable)
 {
   if (pthread_attr_init(&m_attr) != 0)
     throw ThreadException("pthread_attr_init() error", __LINE__, __FILE__);
   if (detach && pthread_attr_setdetachstate(&m_attr, PTHREAD_CREATE_DETACHED) != 0)
     throw ThreadException("pthread_attr_setdetachstate error", __LINE__, __FILE__);
   m_started = false;
 }
开发者ID:Hallelouia,项目名称:LibNet,代码行数:9,代码来源:UnixThread.cpp

示例5: switch

void
MutualExclusion::Unlock()
{
    switch (pthread_mutex_unlock(&mutexTheMutex))
    {
        case 0:         return;
        case EPERM:     throw ThreadException(ThreadException::errMutexNotOwned);
        default:        throw ThreadException(ThreadException::errMutexUnknown);
    }
}
开发者ID:ebichu,项目名称:dd-wrt,代码行数:10,代码来源:mutualexclusion.cpp

示例6: switch

	/**
	 * Signal a event variable, waking up any waiting thread(s).
	 */
	void Event::notify()
	{
		int rc = 0;
		mutex.lock();
		switch (type) {

		case DM1_EVENT_SINGLE:
			if (waitersCount == 0) {
				signaled = true;
			}
			else {
				rc = pthread_cond_signal(&cond); 
			}	
			break;

		case DM1_EVENT_BROADCAST: 
			rc = pthread_cond_broadcast(&cond); 
			break;
		
		}
		mutex.unlock();
		if (rc != 0) {
			fprintf(stderr, "Event.notify: Failed to notify Event: errcode = %d\n", rc);
			throw ThreadException(__FILE__, __LINE__, DM1_ERR_EVENT_NOTIFY, rc);
		}

	}
开发者ID:followheart,项目名称:try-catch-finally,代码行数:30,代码来源:event.cpp

示例7: while

// Sets a new prompt for the user and then gets an entire string from the input
// queue for this thread's node.  If no string present, waits until one is.
char* GameThread::getStr(char* szBuffer, char* szPromptText, short nPromptCol, short nMaxLen)
{
   // Display the new prompt
   gn->print(szPromptText, nPromptCol, 0, OP_COMMAND_PROMPT);

   gs->leaveCritical();
   
   // While there's no input messages waiting, sleep.
   while ( gn->mqInput.isEmpty() )
      {
      Sleep(50);
      }

   gs->enterCritical();
      
   // Retreive the first waiting input message
   InputData idMessage = gn->mqInput.dequeue();

   // If it's an IP_FORCE_EXIT message, shut down this thread.
   if ( idMessage.nType == IP_FORCE_EXIT )
      throw ThreadException();

   // If the message is too long, shorten it.
   if ( strlen(idMessage.szMessage) > nMaxLen && nMaxLen < 190 )
      idMessage.szMessage[nMaxLen] = '\0';
      
   // Copy the message to the buffer and return it.
   strcpy(szBuffer, idMessage.szMessage);
   return szBuffer;
}
开发者ID:evanelias,项目名称:tournament-trivia,代码行数:32,代码来源:gamesrv.cpp

示例8: Warning

Mutex::~Mutex()
{
  if ( locked() )
    Warning( "Destroying mutex when locked" );
  if ( pthread_mutex_destroy( &mMutex ) < 0 )
    throw ThreadException( stringtf( "Unable to destroy pthread mutex: %s", strerror(errno) ) );
}
开发者ID:AaronJorgensen,项目名称:ZoneMinder,代码行数:7,代码来源:zm_thread.cpp

示例9: create

		void create(U callObj, T fctParam) {
			mCallObj  = callObj;
			mFctParam = fctParam;

			if (pthread_create(&mThread, NULL, start_thread_trampoline<U, T>, this) != UnixThread::PTHREAD_SUCCESS)
				throw ThreadException("fail pthread_create()");
		}
开发者ID:navidemad,项目名称:cpp-rtype-shooter-epitech,代码行数:7,代码来源:UnixThread.hpp

示例10: run

	virtual unsigned run() throw(ThreadException)
	{
		Worker::run();
		throw ThreadException("test exception throwing.");

		return 1;
	}
开发者ID:rayfill,项目名称:cpplib,代码行数:7,代码来源:ThreadTest.cpp

示例11: ENTER

	/**
	 * This is the method that should be called to start the Thread
	 */
	void 
	Thread::start() 
	{
		ENTER("Thread.start");
		if (debug)
			fprintf(stdout, "Thread.start: Starting thread %s\n", getName());
#if DM1_USE_PTHREAD
		int rc = pthread_create(&tid, 0, dm1_thread_main, this);
		if (rc != 0) {
#else
		handle = (HANDLE) _beginthreadex(NULL, 0, dm1_thread_main, 
			this, 0, (unsigned int *)&tid);
		//handle = (HANDLE) CreateThread(NULL, 0, dm1_thread_main, 
		//	this, CREATE_SUSPENDED, &tid);
		//if (handle == 0 || ResumeThread(handle) == (DWORD)-1) {
		if (handle == 0) {
			int rc = GetLastError();
#endif
			fprintf(stderr, "Thread.start: Error: Failed to start thread %s\n", getName());
			throw ThreadException(__FILE__, __LINE__, DM1_ERR_THREAD_CREATE, rc);
		}
		EXIT("Thread.start");
	}

	/**
	 * The Thread constructor.
	 */
	Thread::Thread(Runnable *toRun, const char *name, bool isDaemon) : DLinkable()
	{
		ENTER("Thread.ctor");
		status = DM1_THREAD_UNUSED;
		this->isDaemon = isDaemon;
		this->toRun = toRun;
		toRun->setThread(this);
		latchMode = 0;
		isSignaled = 0;
		this->name = strdup(name);
		status = DM1_THREAD_INITED;
		EXIT("Thread.ctor");
	}

	/**
	 * Terminates the thread.
	 */
	void 
	Thread::exit()
	{
		ENTER("Thread.exit");
		if (debug)
			fprintf(stdout, "Thread.exit: Exiting thread %s\n", getName());
	#if !DM1_USE_PTHREAD
		cleanup();
		_endthreadex(0);
		//ExitThread(0);
	#else
		pthread_exit(0);
	#endif
		EXIT("Thread.exit");
	}
开发者ID:followheart,项目名称:try-catch-finally,代码行数:62,代码来源:thread.cpp

示例12: GetLastError

	void Event::reset()
	{
		if (!ResetEvent(event)) {
			DWORD rc = GetLastError();
			fprintf(stderr, "Event.reset: Failed to reset an Event: errcode = %d\n", rc);
			throw ThreadException(__FILE__, __LINE__, DM1_ERR_EVENT_RESET, rc);
		}
	}
开发者ID:followheart,项目名称:try-catch-finally,代码行数:8,代码来源:event.cpp

示例13: strerror

 void CommonThread::start() {
     if(!this->_create){
         if(pthread_create(&this->thread_info.thread_id, NULL, start_thread, (void*)this) != 0) {
             stringstream error;
             error << "[create] create thread failed:" << strerror(errno) << endl;
             throw ThreadException(error.str());
         }
         if (this->thread_info.detach == E_THREAD_DETACHED) {
             cout << "Detached Thread:" << this->thread_info.name << endl;
             if (pthread_detach(this->thread_info.thread_id)) {
                 throw ThreadException("[detach] can't create detached thread");
             }
         }
         this->_create = T_TRUE;
         this->thread_info.state = E_THREAD_RUNNING;
     }
 }
开发者ID:eager7,项目名称:thread_demo,代码行数:17,代码来源:CommonThread.cpp

示例14: getTimeout

bool Condition::wait( double secs )
{
  // Locking done outside of this function
  struct timespec timeout = getTimeout( secs );
  if ( pthread_cond_timedwait( &mCondition, mMutex.getMutex(), &timeout ) < 0 && errno != ETIMEDOUT )
    throw ThreadException( stringtf( "Unable to timedwait pthread condition: %s", strerror(errno) ) );
  return( errno != ETIMEDOUT );
}
开发者ID:AaronJorgensen,项目名称:ZoneMinder,代码行数:8,代码来源:zm_thread.cpp

示例15: pthread_mutex_trylock

bool Mutex::locked()
{
  int state = pthread_mutex_trylock( &mMutex );
  if ( state != 0 && state != EBUSY )
    throw ThreadException( stringtf( "Unable to trylock pthread mutex: %s", strerror(errno) ) );
  if ( state != EBUSY )
    unlock();
  return( state == EBUSY );
}
开发者ID:AaronJorgensen,项目名称:ZoneMinder,代码行数:9,代码来源:zm_thread.cpp


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