本文整理汇总了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));
}
}
示例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();
}
示例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();
}
示例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)));
}
}
示例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);
}
//.........这里部分代码省略.........
示例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)));
}
}