本文整理汇总了C++中ThreadPtr::start方法的典型用法代码示例。如果您正苦于以下问题:C++ ThreadPtr::start方法的具体用法?C++ ThreadPtr::start怎么用?C++ ThreadPtr::start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ThreadPtr
的用法示例。
在下文中一共展示了ThreadPtr::start方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void
MyObjectI::amdAddWithRetry_async(const Test::AMD_MyObject_amdAddWithRetryPtr& cb, int x, int y, const Ice::Current& current)
{
class ThreadI : public Thread
{
public:
ThreadI(const Test::AMD_MyObject_amdAddWithRetryPtr& cb, int x, int y) :
_cb(cb),
_x(x),
_y(y)
{
}
void run()
{
ThreadControl::sleep(Time::milliSeconds(10));
_cb->ice_response(_x + _y);
}
private:
Test::AMD_MyObject_amdAddWithRetryPtr _cb;
int _x;
int _y;
};
ThreadPtr thread = new ThreadI(cb, x, y);
thread->start().detach();
Ice::Context::const_iterator p = current.ctx.find("retry");
if(p == current.ctx.end() || p->second != "no")
{
throw Test::RetryException(__FILE__, __LINE__);
}
}
示例2: EventHandlerThread
ThreadPool::ThreadPool(int size , int sizeMax, int sizeWarn,int listSizeMax,int stackSize) :
_destroyed(false),
_listSize( 0 ),
_procSize( 0 ),
_listSizeMax( listSizeMax),
_size(size),
_sizeMax(sizeMax),
_sizeWarn(sizeWarn),
_stackSize(0),
_running(0),
_inUse(0),
_load(1.0),
_promote(true),
_waitingNumber(0)
{
if ( size < 1 )
size = 1;
if ( sizeMax < size )
sizeMax = size;
if ( sizeWarn > sizeMax )
sizeWarn = sizeMax;
if ( stackSize < 0 )
stackSize = 16 * 1024 * 1024;
const_cast<int&>(_size) = size;
const_cast<int&>(_sizeMax) = sizeMax;
const_cast<int&>(_sizeWarn) = sizeWarn;
const_cast<size_t&>(_stackSize) = static_cast<size_t>(stackSize);
try
{
for(int i = 0 ; i < _size ; ++i)
{
ThreadPtr thread = new EventHandlerThread(this);
thread->start(_stackSize);
_threads.push_back(thread);
++_running;
}
}
catch(const Exception& ex)
{
destroy();
joinWithAllThreads();
}
}
示例3: promoteFollower
void ThreadPool::promoteFollower( pthread_t thid )
{
if(_sizeMax > 1)
{
this->lock();
assert(!_promote);
_promote = true;
this->notify();
if(!_destroyed)
{
assert(_inUse >= 0);
++_inUse;
if(_inUse == _sizeWarn)
{
}
assert(_inUse <= _running);
if(_inUse < _sizeMax && _inUse == _running)
{
try
{
ThreadPtr thread = new EventHandlerThread(this);
thread->start(_stackSize);
_threads.push_back(thread);
++_running;
}
catch(const Exception& ex)
{
throw ThreadCreateException(__FILE__,__LINE__);
}
}
}
this->unlock();
}
}
示例4: catch
void
PriorityInversionTest::run()
{
int cores, high, medium, low, timeout;
timeout = 30;
#ifdef _WIN32
return; //Priority inversion is not supported by WIN32
#else
try
{
IceUtil::Mutex m;
}
catch(const IceUtil::ThreadSyscallException&)
{
return; // Mutex protocol PrioInherit not supported
}
cores = static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN));
high = 45;
medium = 35;
low = 1;
#endif
{
Monitor<Mutex> monitor;
TaskCollectorPtr collector = new TaskCollector(cores, high, medium, low, monitor);
vector<ThreadControl> threads;
SharedResourcePtr shared = new SharedResourceMutex(collector);
//
// Create one low priority thread.
//
TaskPtr lowThread = new Task(shared);
threads.push_back(lowThread->start(128, low));
lowThread->waitAcquired();
//
// Create one high priority thread that use the same shared resource
// as the previous low priority thread
//
TaskPtr highThread = new Task(shared);
threads.push_back(highThread->start(128, high));
//
// Create one medium priority thread per core.
//
for(int cont = 0; cont < cores; ++cont)
{
ThreadPtr t = new MediumPriorityThread(collector, highThread, timeout);
threads.push_back(t->start(128, medium));
}
//
// Join with all the threads.
//
vector<ThreadControl>::iterator it;
for(it = threads.begin(); it != threads.end(); ++it)
{
try
{
(*it).join();
}
catch(...)
{
}
}
}
//
// Same test with a recursive mutex.
//
{
Monitor<Mutex> monitor;
TaskCollectorPtr collector = new TaskCollector(cores, high, medium, low, monitor);
SharedResourcePtr shared = new SharedResourceRecMutex(collector);
vector<ThreadControl> threads;
//
// Create one low priority thread.
//
TaskPtr lowThread = new Task(shared);
threads.push_back(lowThread->start(128, low));
lowThread->waitAcquired();
//
// Create one high priority thread that use the same shared resource
// as the previous low priority thread.
//
ThreadPtr highThread = new Task(shared);
threads.push_back(highThread->start(128, high));
//
// Create one medium priority tasks per core that runs until
// the high priority thread is running.
//
for(int cont = 0; cont < cores; ++cont)
{
ThreadPtr t = new MediumPriorityThread(collector, highThread, timeout);
//.........这里部分代码省略.........