本文整理汇总了C++中Thread::Start方法的典型用法代码示例。如果您正苦于以下问题:C++ Thread::Start方法的具体用法?C++ Thread::Start怎么用?C++ Thread::Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thread
的用法示例。
在下文中一共展示了Thread::Start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Test
void SuiteStartStop::Test()
{
Thread* threadA = new TestThread("THDA", 'A');
Thread* threadB = new TestThread("THDB", 'B');
TEST( ((Thread&) *threadA) == ((Thread&) *threadA) );
TEST( ((Thread&) *threadA) != ((Thread&) *threadB) );
threadA->Start();
threadB->Start();
for( TUint i = 0 ; i< 10; ++i) {
TEST(gTestStack->IsEmpty());
threadA->Signal();
// use sleeps to avoid dependency on thread priorities being supported
Thread::Sleep(kSleepMs);
TEST(gTestStack->Pop('A'));
threadB->Signal();
Thread::Sleep(kSleepMs);
TEST(gTestStack->Pop('B'));
threadA->Signal();
Thread::Sleep(kSleepMs);
TEST(gTestStack->Pop('A'));
}
TEST(gTestStack->IsEmpty());
delete threadA;
delete threadB;
}
示例2: test_rwlock
void test_rwlock(Ardb& db)
{
WriteTask wtask;
ReadTask rtask;
std::map<int, int> mm;
SpinRWLock lock;
wtask.lock = &lock;
wtask.mm = &mm;
rtask.lock = &lock;
rtask.mm = &mm;
Thread* w = new Thread(&wtask);
std::vector<Thread*> ts;
for(uint32 i = 0; i < 10; i++)
{
Thread* r = new Thread(&rtask);
r->Start();
ts.push_back(r);
}
w->Start();
w->Join();
std::vector<Thread*>::iterator tit = ts.begin();
while(tit != ts.end())
{
(*tit)->Join();
tit++;
}
INFO_LOG("mm size=%u", mm.size());
}
示例3: CreateThreadPool
int ThreadPool::CreateThreadPool()
{
for(int i = 0; i<getMaxThreadsNumber(); i++)
{
int rc = 0;
//init lock
Thread* th = static_cast< Thread* >(new CommonSocketThread());
/// used to
th->setInitLocker( &m_initThread );
th->setLocker( &m_worksLock );
th->setThreadId(i);
m_initThread.lock();
rc = th->Start();
th->getCondition().wait(&m_initThread);
m_initThread.unlock();
assert(rc == 0);
m_threadMap.insert( make_pair(i, th) );
}
return 0;
}
示例4: TestThread
void TestThread()
{
Thread* th = new MainTestThread();
th->Start();
th->Wait();
delete th;
}
示例5: Execute
bool ThreadPoolImpl::Execute(Runnable *pRunnable)
{
if (0 == pRunnable || !m_bCreate) {
return false;
}
bool bRet = false;
if (m_tasks.size() >= m_nMaxPendingTask)
{
if (m_threads.size() < m_nMaxThread) {
Thread *pThread = new Thread(new ThreadPoolImpl::Worker(this, pRunnable));
if (0 != pThread) {
TAutoLock lock(m_mtxThread);
m_threads.push_back(pThread);
pThread->Start();
bRet = true;
}
}
else {
// abandon the task.
bRet = false;
}
}
else
{
TAutoLock lock(m_mtxTasks);
m_tasks.push_back(pRunnable);
bRet = true;
}
return bRet;
}
示例6: TestTimer
void TestTimer(Environment& aEnv)
{
Thread* th = new TimerTestThread(aEnv);
th->Start();
th->Wait();
delete th;
}
示例7: Window2_Created
void Window2_Created(Win32Window* window)
{
glwindow = window;
worker.Attach(&THREAD_Run);
worker.Start();
}
示例8: TestNetwork
void TestNetwork(const std::vector<Brn>& aArgs)
{
OptionParser parser;
OptionUint adapter("-i", "--interface", 0, "index of network adapter to use");
parser.AddOption(&adapter);
if (!parser.Parse(aArgs) || parser.HelpDisplayed()) {
return;
}
std::vector<NetworkAdapter*>* ifs = Os::NetworkListAdapters(Net::InitialisationParams::ELoopbackUse, "TestNetwork");
ASSERT(ifs->size() > 0 && adapter.Value() < ifs->size());
TIpAddress addr = (*ifs)[adapter.Value()]->Address();
for (TUint i=0; i<ifs->size(); i++) {
(*ifs)[i]->RemoveRef("TestNetwork");
}
delete ifs;
Endpoint endpt(0, addr);
Endpoint::AddressBuf buf;
endpt.AppendAddress(buf);
Print("Using network interface %s\n\n", buf.Ptr());
Thread* th = new MainNetworkTestThread(addr);
th->Start();
th->Wait();
delete th;
}
示例9: Create
bool ThreadPoolImpl::Create(unsigned int nMinThread, unsigned int nMaxThread, unsigned int nMaxPendingTask)
{
if (m_bCreate) { // disallow recreate operation.
return true; // discard the recreate parameters (i.e. nMin, nMax, nMax)
}
if (0 == nMinThread || nMinThread > nMaxThread) {
return false;
}
m_nMinThread = nMinThread;
m_nMaxThread = nMaxThread;
m_nMaxPendingTask = nMaxPendingTask;
unsigned int i = 0;
for (; i < m_nMinThread; ++i)
{
Thread *pThread = new Thread(new ThreadPoolImpl::Worker(this, 0));
if (0 == pThread) {
break;
}
TAutoLock lock(m_mtxThread);
m_threads.push_back(pThread);
pThread->Start();
}
m_bCreate = i > 0 ? true : false;
return m_bCreate;
}
示例10: FlushAll
int Ardb::FlushAll()
{
struct VisitorTask: public RawValueVisitor, public Thread
{
Ardb* db;
VisitorTask(Ardb* adb) :
db(adb)
{
}
int OnRawKeyValue(const Slice& key, const Slice& value)
{
db->RawDel(key);
return 0;
}
void Run()
{
db->GetEngine()->BeginBatchWrite();
db->VisitAllDB(this);
db->GetEngine()->CommitBatchWrite();
db->GetEngine()->CompactRange(Slice(), Slice());
delete this;
}
};
/*
* Start a background thread to delete kvs
*/
Thread* t = new VisitorTask(this);
t->Start();
return 0;
}
示例11: CompactDB
int Ardb::CompactDB(const DBID& db)
{
struct CompactTask: public Thread
{
Ardb* adb;
DBID dbid;
CompactTask(Ardb* db, DBID id) :
adb(db), dbid(id)
{
}
void Run()
{
KeyObject start(Slice(), KV, dbid);
KeyObject end(Slice(), KV, dbid + 1);
Buffer sbuf, ebuf;
encode_key(sbuf, start);
encode_key(ebuf, end);
adb->GetEngine()->CompactRange(sbuf.AsString(), ebuf.AsString());
delete this;
}
};
/*
* Start a background thread to compact kvs
*/
Thread* t = new CompactTask(this, db);
t->Start();
return 0;
}
示例12: TestThread
void TestThread()
{
gTestStack = new TestStack();
Thread* th = new MainTestThread();
th->Start();
th->Wait();
delete th;
delete gTestStack;
}
示例13: main
int main(int argc, char **argv)
{
Thread *thread = new Thread();
thread->SetThreadType(ThreadTypeIntervalBased, 10);
TestTask *task = new TestTask();
thread->AddTask(task);
thread->Start();
}
示例14: Mail
bool Mail(NickCore *nc, const Anope::string &subject, const Anope::string &message)
{
if (!Config->UseMail || !nc || nc->email.empty() || subject.empty() || message.empty())
return false;
nc->lastmail = Anope::CurTime;
Thread *t = new MailThread(nc->display, nc->email, subject, message);
t->Start();
return true;
}
示例15: StartReceiveData
void TcpClient::StartReceiveData(void(*ReceiveFunction) (char*, int))
{
__PRIVATE_TCPCLIENT::ReceiveDataParameter* parameter = new (__PRIVATE_TCPCLIENT::ReceiveDataParameter);
parameter->ReceiveFunction = ReceiveFunction;
parameter->ConnectionLostFunction = ConnectionLost;
parameter->Socket = _socket,
parameter->BufferSize = _bufferSize;
Thread thread = Thread(__PRIVATE_TCPCLIENT::ReceiveData, parameter);
thread.Start();
}