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


C++ Thread::Start方法代码示例

本文整理汇总了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;
}
开发者ID:Jacik,项目名称:ohNet,代码行数:31,代码来源:TestThread.cpp

示例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());
}
开发者ID:DirektSPEED,项目名称:ardb,代码行数:28,代码来源:misc_testcase.cpp

示例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;
}
开发者ID:euiseo80,项目名称:JasterEmbeddedServer,代码行数:27,代码来源:ThreadPool.cpp

示例4: TestThread

void TestThread()
{
    Thread* th = new MainTestThread();
    th->Start();
    th->Wait();
    delete th;
}
开发者ID:astaykov,项目名称:ohNet,代码行数:7,代码来源:TestThread.cpp

示例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;
}
开发者ID:meanx,项目名称:etl,代码行数:32,代码来源:ThreadPool.cpp

示例6: TestTimer

void TestTimer(Environment& aEnv)
{
    Thread* th = new TimerTestThread(aEnv);
    th->Start();
    th->Wait();
    delete th;
}
开发者ID:Montellese,项目名称:ohNet,代码行数:7,代码来源:TestTimer.cpp

示例7: Window2_Created

void Window2_Created(Win32Window* window)
{
	glwindow = window;

	worker.Attach(&THREAD_Run);
	worker.Start();
}
开发者ID:IwishIcanFLighT,项目名称:Asylum_Tutorials,代码行数:7,代码来源:window2.cpp

示例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;
}
开发者ID:chinshou,项目名称:ohNet,代码行数:25,代码来源:TestNetwork.cpp

示例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;
}
开发者ID:meanx,项目名称:etl,代码行数:29,代码来源:ThreadPool.cpp

示例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;
	}
开发者ID:kouhate,项目名称:ardb,代码行数:30,代码来源:ardb.cpp

示例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;
	}
开发者ID:kouhate,项目名称:ardb,代码行数:28,代码来源:ardb.cpp

示例12: TestThread

void TestThread()
{
    gTestStack = new TestStack();
    Thread* th = new MainTestThread();
    th->Start();
    th->Wait();
    delete th;
    delete gTestStack;
}
开发者ID:Jacik,项目名称:ohNet,代码行数:9,代码来源:TestThread.cpp

示例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();
}
开发者ID:bitpick,项目名称:libtaskprocpp,代码行数:10,代码来源:test_thread.cpp

示例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;
}
开发者ID:xxgrunge,项目名称:anope196,代码行数:11,代码来源:mail.cpp

示例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();
		}
开发者ID:Rottinator,项目名称:Base.h,代码行数:11,代码来源:tcpClient.cpp


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