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


C++ ThreadControl::join方法代码示例

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


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

示例1: StartTestThread

void
StartTest::run()
{
    //
    // Check that calling start() more than once raises ThreadStartedException.
    //
    StartTestThreadPtr t = new StartTestThread();
    ThreadControl control = t->start();
    control.join();
    try
    {
        t->start();
        test(false);
    }
    catch(const ThreadStartedException&)
    {
    }

    //
    // Now let's create a bunch of short-lived threads
    //
    for(int i = 0; i < 50; i++)
    {
        for(int j = 0; j < 50; j++)
        {
            Thread* t = new StartTestThread;
            t->start().detach();
        }
        ThreadControl::sleep(Time::milliSeconds(5));
    }
}
开发者ID:2008hatake,项目名称:zeroc-ice,代码行数:31,代码来源:StartTest.cpp

示例2: lock

void
RecMutexTest::run()
{
    RecMutex mutex;
    RecMutexTestThreadPtr t;
    ThreadControl control;

    {
        RecMutex::Lock lock(mutex);
        
        // TEST: lock twice
        RecMutex::Lock lock2(mutex);

        // TEST: TryLock
        RecMutex::TryLock lock3(mutex);
        test(lock3.acquired());
        
        // TEST: Start thread, try to acquire the mutex.
        t = new RecMutexTestThread(mutex);
        control = t->start();
        
        // TEST: Wait until the tryLock has been tested.
        t->waitTryLock();
        
    }

    //
    // TEST: Once the recursive mutex has been released, the thread
    // should acquire the mutex and then terminate.
    //

    control.join();
   
}
开发者ID:Jonavin,项目名称:ice,代码行数:34,代码来源:RecMutexTest.cpp

示例3: lock

void
MutexTest::run()
{
    Mutex mutex;
    MutexTestThreadPtr t;
    ThreadControl control;

    {
        Mutex::Lock lock(mutex);

        // LockT testing: 
        //

        test(lock.acquired());

        try
        {
            lock.acquire();
            test(false);
        }
        catch(const ThreadLockedException&)
        {
            // Expected
        }

        try
        {
            lock.tryAcquire();
            test(false);
        }
        catch(const ThreadLockedException&)
        {
            // Expected
        }

        test(lock.acquired());
        lock.release();
        test(!lock.acquired());

        try
        {
            lock.release();
            test(false);
        }
        catch(const ThreadLockedException&)
        {
            // Expected
        }
        
        Mutex::TryLock lock2(mutex);
        try
        {
            test(lock.tryAcquire() == false);
        }
        catch(const ThreadLockedException&)
        {
        }
        lock2.release();
        test(lock.tryAcquire() == true);
        test(lock.acquired());  

        // Deadlock testing
        //

#if !defined(NDEBUG) && !defined(_WIN32)
        try
        {
            Mutex::Lock lock3(mutex);
            test(false);
        }
        catch(const ThreadLockedException&)
        {    
            // Expected
        }
#endif

        // TEST: Start thread, try to acquire the mutex.
        t = new MutexTestThread(mutex);
        control = t->start();
        
        // TEST: Wait until the tryLock has been tested.
        t->waitTryLock();
    }

    //
    // TEST: Once the mutex has been released, the thread should
    // acquire the mutex and then terminate.
    //
    control.join();
}
开发者ID:465060874,项目名称:ice,代码行数:90,代码来源:MutexTest.cpp

示例4: lock

void
MonitorRecMutexTest::run()
{
    Monitor<RecMutex> monitor;
    MonitorRecMutexTestThreadPtr t;
    MonitorRecMutexTestThread2Ptr t2;
    MonitorRecMutexTestThread2Ptr t3;
    ThreadControl control;
    ThreadControl control2;


    {
        Monitor<RecMutex>::Lock lock(monitor);

        Monitor<RecMutex>::TryLock lock2(monitor);
        test(lock2.acquired());
        
        // TEST: TryLock
        
        Monitor<RecMutex>::TryLock tlock(monitor);
        test(tlock.acquired());
        
        // TEST: Start thread, try to acquire the mutex.
        t = new MonitorRecMutexTestThread(monitor);
        control = t->start();
        
        // TEST: Wait until the tryLock has been tested.
        t->waitTryLock();
    }

    //
    // TEST: Once the mutex has been released, the thread should
    // acquire the mutex and then terminate.
    //
    control.join();

    // TEST: notify() wakes one consumer.
    t2 = new MonitorRecMutexTestThread2(monitor);
    control = t2->start();
    t3 = new MonitorRecMutexTestThread2(monitor);
    control2 = t3->start();

    // Give the thread time to start waiting.
    ThreadControl::sleep(Time::seconds(1));

    {
        Monitor<RecMutex>::Lock lock(monitor);
        monitor.notify();
    }

    // Give one thread time to terminate
    ThreadControl::sleep(Time::seconds(1));

    test((t2->finished && !t3->finished) || (t3->finished && !t2->finished));

    {
        Monitor<RecMutex>::Lock lock(monitor);
        monitor.notify();
    }
    control.join();
    control2.join();

    // TEST: notifyAll() wakes one consumer.
    t2 = new MonitorRecMutexTestThread2(monitor);
    control = t2->start();
    t3 = new MonitorRecMutexTestThread2(monitor);
    control2 = t3->start();

    // Give the threads time to start waiting.
    ThreadControl::sleep(Time::seconds(1));

    {
        Monitor<RecMutex>::Lock lock(monitor);
        monitor.notifyAll();
    }

    control.join();
    control2.join();

    // TEST: timedWait
    {
        Monitor<RecMutex>::Lock lock(monitor);
        test(!monitor.timedWait(Time::milliSeconds(500)));
    }
}
开发者ID:2008hatake,项目名称:zeroc-ice,代码行数:85,代码来源:MonitorRecMutexTest.cpp

示例5: TestBase

ThreadPriorityTest::ThreadPriorityTest() :
    TestBase(priorityTestName)
{
#ifdef _WIN32
    ThreadControl c;
    try
    {
        PriorityTestThreadPtr t1 = new PriorityTestThread();
        c = t1->start(128, THREAD_PRIORITY_IDLE);
        c.join();
        test(t1->getPriority() == THREAD_PRIORITY_IDLE);

        t1 = new PriorityTestThread();
        c = t1->start(128, THREAD_PRIORITY_LOWEST);
        c.join();
        test(t1->getPriority() == THREAD_PRIORITY_LOWEST);

        t1 = new PriorityTestThread();
        c = t1->start(128, THREAD_PRIORITY_BELOW_NORMAL);
        c.join();
        test(t1->getPriority() == THREAD_PRIORITY_BELOW_NORMAL);

        t1 = new PriorityTestThread();
        c = t1->start(128, THREAD_PRIORITY_NORMAL);
        c.join();
        test(t1->getPriority() == THREAD_PRIORITY_NORMAL);

        t1 = new PriorityTestThread();
        c = t1->start(128, THREAD_PRIORITY_ABOVE_NORMAL);
        c.join();
        test(t1->getPriority() == THREAD_PRIORITY_ABOVE_NORMAL);

        t1 = new PriorityTestThread();
        c = t1->start(128, THREAD_PRIORITY_HIGHEST);
        c.join();
        test(t1->getPriority() == THREAD_PRIORITY_HIGHEST);

        t1 = new PriorityTestThread();
        c = t1->start(128, THREAD_PRIORITY_TIME_CRITICAL);
        c.join();
        test(t1->getPriority() == THREAD_PRIORITY_TIME_CRITICAL);
    }
    catch(...)
    {
        test(false);
    }

    //
    // Test to set invalid priorities too high
    //
    try
    {
        PriorityTestThreadPtr t1 = new PriorityTestThread();
        c = t1->start(128, THREAD_PRIORITY_TIME_CRITICAL + 10);
        test(false);
    }
    catch(const ThreadSyscallException&)
    {
        //Expected
    }
    catch(...)
    {
        test(false);
    }

    //
    // Test to set invalid priorities too low
    //
    try
    {
        PriorityTestThreadPtr t1 = new PriorityTestThread();
        c = t1->start(128, THREAD_PRIORITY_IDLE - 10);
        test(false);
    }
    catch(const ThreadSyscallException&)
    {
        //Expected
    }
    catch(...)
    {
        test(false);
    }

#else

    ThreadControl c;
    try
    {
        for(int cont = 1; cont < 10; ++cont)
        {
            PriorityTestThreadPtr t1 = new PriorityTestThread();
            c = t1->start(128, cont);
            c.join();
            test(t1->getPriority() == cont);
        }
    }
    catch(...)
    {
        test(false);
    }
//.........这里部分代码省略.........
开发者ID:pedia,项目名称:zeroc-ice,代码行数:101,代码来源:ThreadPriority.cpp

示例6: lock

void
MonitorMutexTest::run()
{
    Monitor<Mutex> monitor;
    MonitorMutexTestThreadPtr t;
    MonitorMutexTestThread2Ptr t2;
    MonitorMutexTestThread2Ptr t3;
    ThreadControl control;
    ThreadControl control2;

    {
        Monitor<Mutex>::Lock lock(monitor);

        try
        {
            Monitor<Mutex>::TryLock tlock(monitor);
            test(!tlock.acquired());
        }
        catch(const ThreadLockedException&)
        {
            //
            // pthread_mutex_trylock returns EDEADLK in FreeBSD's new threading implementation
            // as well as in Fedora Core 5.
            //
        }

        // TEST: Start thread, try to acquire the mutex.
        t = new MonitorMutexTestThread(monitor);
        control = t->start();

        // TEST: Wait until the tryLock has been tested.
        t->waitTryLock();
    }

    //
    // TEST: Once the mutex has been released, the thread should
    // acquire the mutex and then terminate.
    //
    control.join();

    // TEST: notify() wakes one consumer.
    t2 = new MonitorMutexTestThread2(monitor);
    control = t2->start();
    t3 = new MonitorMutexTestThread2(monitor);
    control2 = t3->start();

    // Give the thread time to start waiting.
    ThreadControl::sleep(Time::seconds(1));

    {
        Monitor<Mutex>::Lock lock(monitor);
        monitor.notify();
    }

    // Give one thread time to terminate
    ThreadControl::sleep(Time::seconds(1));

    test((t2->finished && !t3->finished) || (t3->finished && !t2->finished));

    {
        Monitor<Mutex>::Lock lock(monitor);
        monitor.notify();
    }
    control.join();
    control2.join();

    // TEST: notifyAll() wakes one consumer.
    t2 = new MonitorMutexTestThread2(monitor);
    control = t2->start();
    t3 = new MonitorMutexTestThread2(monitor);
    control2 = t3->start();

    // Give the threads time to start waiting.
    ThreadControl::sleep(Time::seconds(1));

    {
        Monitor<Mutex>::Lock lock(monitor);
        monitor.notifyAll();
    }

    control.join();
    control2.join();

    // TEST: timedWait
    {
        Monitor<Mutex>::Lock lock(monitor);

        try
        {
            monitor.timedWait(Time::milliSeconds(-1));
            test(false);
        }
        catch(const IceUtil::InvalidTimeoutException&)
        {
        }

        test(!monitor.timedWait(Time::milliSeconds(500)));
    }
}
开发者ID:joshmoore,项目名称:ice,代码行数:99,代码来源:MonitorMutexTest.cpp


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