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


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

本文整理汇总了C++中Thread::Wait方法的典型用法代码示例。如果您正苦于以下问题:C++ Thread::Wait方法的具体用法?C++ Thread::Wait怎么用?C++ Thread::Wait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Thread的用法示例。


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

示例1: MultipleWriteTest

void MultipleWriteTest(Thread& aCurrentThread, TUint aRPriority, TUint aW0Priority, TUint aW1Priority)
{
    const TUint writer0Iters = 300;
    const TUint writer1Iters = 500;
    FifoTest q(32);
    Writer0 writer0(q, aCurrentThread,  writer0Iters);
    Functor fWriter0 = MakeFunctor(writer0, &Writer0::Run);
    Writer1 writer1(q, aCurrentThread, writer1Iters);
    Functor fWriter1 = MakeFunctor(writer1, &Writer1::Run);
    Reader reader(q, aCurrentThread, writer0Iters + writer1Iters);
    Functor fReader = MakeFunctor(reader, &Reader::Run);

    ThreadFunctor* tReader0 = new ThreadFunctor("TSTA", fReader, aRPriority);
    ThreadFunctor* tWriter0 = new ThreadFunctor("TSTB", fWriter0, aW0Priority);
    ThreadFunctor* tWriter1 = new ThreadFunctor("TSTC", fWriter1, aW1Priority);
    tReader0->Start();
    tWriter0->Start();
    tWriter1->Start();

    aCurrentThread.Wait();
    aCurrentThread.Wait();
    aCurrentThread.Wait();

    // The worker threads should be ready to remove.
    delete tReader0;
    delete tWriter0;
    delete tWriter1;
}
开发者ID:ACDN,项目名称:ohNet,代码行数:28,代码来源:TestFifo.cpp

示例2: MutexTutorial

void MutexTutorial()
{
	/// .`Mutex`
	
	/// Mutex ("mutual exclusion") is a well known concept in multithreaded programming: When
	/// multiple threads write and read the same data, the access has to be serialized using
	/// Mutex. Following invalid code demonstrates why:
	
	Thread t;
	
	int sum = 0;
	t.Run([&sum] {
		for(int i = 0; i < 1000000; i++)
			sum++;
	});
	
	for(int i = 0; i < 1000000; i++)
		sum++;
	
	t.Wait();
	DUMP(sum);
	
	/// While the expected value is 2000000, produced value is different. The problem is that
	/// both thread read / modify / write `sum` value without any locking. Using `Mutex` locks
	/// the `sum` and thus serializes access to it - read / modify / write sequence  is now
	/// exclusive for the thread that has `Mutex` locked, this fixing the issue. `Mutex` can be
	/// locked / unlocked with `Enter` / `Leave` methods. Alternatively, `Mutex::Lock` helper
	/// class locks `Mutex` in constructor and unlocks it in destructor:
	
	Mutex m;
	sum = 0;
	t.Run([&sum, &m] {
		for(int i = 0; i < 1000000; i++) {
			m.Enter();
			sum++;
			m.Leave();
		}
	});
	
	for(int i = 0; i < 1000000; i++) {
		Mutex::Lock __(m); // Lock m till the end of scope
		sum++;
	}
	
	t.Wait();
	DUMP(sum);
	
	///
}
开发者ID:ultimatepp,项目名称:mirror,代码行数:49,代码来源:Mutex.cpp

示例3: 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

示例4: TestThread

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

示例5: TestTimer

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

示例6: TestThread

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


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