• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ ThreadControl类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

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


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


示例3: sender

void EditAccountDialog::chooseQuery()
{
        ThreadControl *tc = qobject_cast<ThreadControl *>( sender() );
        if( !tc )
            return;

        int i = tc->getIndexOfLastQuery( qList );
        if( i < 0 )
            return;

        QStringList list = tc->getDataList();

	switch(i)
	{
		case 0:
		{
                    if( list.count() >= 1 )
                        loadData( list.first() );
                    break;
		}
		case 1:
                {
                        if( list.count() >= 1 )
                            checkAnswer( list.first() );
                        break;
                }
                case 2:
                {
                        if( list.count() >=1 )
                            changeOwnerAnswer( list.first() );
                        break;
                }
	}
}
开发者ID:petrpopov,项目名称:db_transactions,代码行数:34,代码来源:editaccountdialog.cpp


示例4: sender

void AddClientDialog::loadQuery()
{
    ThreadControl *tc = qobject_cast<ThreadControl *>( sender() );
    if( !tc )
        return;

    int i = tc->getIndexOfLastQuery( qList );
    if( i < 0 )
        return;

    QStringList list = tc->getDataList();
    switch(i)
    {
        case 0:
        {
            checkData( list );
            break;
        }
        case 1:
        {
            if( list.count() > 0 )
                insertData( list.first() );
            break;
        }
    }
}
开发者ID:petrpopov,项目名称:db_transactions,代码行数:26,代码来源:addclientdialog.cpp


示例5: sender

void TransactionWidget::loadQuery()
{
        ThreadControl *tc = qobject_cast<ThreadControl *>( sender() );
        if( !tc )
            return;

        int i = tc->getIndexOfLastQuery( qList );
        if( i < 0 )
                return;

        QString str = tc->getData();

	switch(i)
	{
		case 0:
			{
				loadHeader( str );
				break;
			}
		case 1:
		case 4:
		case 5:
			{
				loadTransactions( str );
				break;
			}
		case 2:
			{
				clearTransaction( str );
				break;
			}
		case 3:
			{
				loadAccount( str );
				break;
			}
		case 6:
		case 7:
			{
				loadAccountSaldo( str );
				break;
			}
	}
}
开发者ID:petrpopov,项目名称:db_transactions,代码行数:44,代码来源:transactionwidget.cpp


示例6: sender

void AccountWidget::chooseQuery()
{
        ThreadControl *tc = qobject_cast<ThreadControl *>( sender() );
        if( !tc )
            return;

        int i = tc->getIndexOfLastQuery( qList );
        if( i < 0 )
            return;

        QString str = tc->getData();
	info->showProgressBar( false );

	switch(i)
	{
		case 0:
			{
				loadCurency( str );
				break;
			}
		case 1:
			{
				disconnect( tableWidget, SIGNAL( rowSelected(int) ), this, SLOT( selectRow(int) ) );

				loadAccount(str);
				tableWidget->SetFocus(lastRow);
				connect( tableWidget, SIGNAL( rowSelected(int) ), this, SLOT( selectRow(int) ) );
				break;
			}
		case 2:
			{
				loadStats( str );
				break;
			}
		case 3:
			{
				checkDeleteAnswer( str );
				break;
			}
	}
}
开发者ID:petrpopov,项目名称:db_transactions,代码行数:41,代码来源:accountwidget.cpp


示例7: sender

void AddCourseDialog::loadQuery()
{
        ThreadControl *tc = qobject_cast<ThreadControl *>( sender() );
        if( !tc )
            return;

        int i = tc->getIndexOfLastQuery( qList );
        if( i < 0 )
            return;

        QStringList list = tc->getDataList();
	info->showProgressBar( false );

	if( i < 0 )
		return;

	switch(i)
	{
		case 0:
			{
                                if( list.count() > 0 )
                                    loadCurrency( list.first() );
				break;
			}
		case 1:
                        {
                                if( list.count() > 0 )
                                    loadAnswer( list.first() );
				break;
			}
		case 2:
			{
                                if( list.count() > 0 )
                                    checkSaleAnswer( list.first() );
				break;
			}
	}
}
开发者ID:petrpopov,项目名称:db_transactions,代码行数:38,代码来源:addcoursedialog.cpp


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


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


示例10: id

bool
IceUtil::ThreadControl::operator!=(const ThreadControl& rhs) const
{
    return id() != rhs.id();
}
开发者ID:zeroc-ice,项目名称:ice-debian-packaging,代码行数:5,代码来源:Thread.cpp


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


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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ThreadData类代码示例发布时间:2022-05-31
下一篇:
C++ ThreadContext类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap