Exemplo n.º 1
0
int main ( int argc,  char** argv )
{
    const int NoOfThreads = 4 ;
    const int NoOfJobs = NoOfThreads * 4  ; // number of jobs for every thread
    const int Multiplier = 250; // [0..9]* Multiplier sleep time for each job
    ThreadWeaver::setDebugLevel ( true, 4);
    QCoreApplication app ( argc,  argv );
    ThreadWeaver::Weaver weaver;
    weaver.setMaximumNumberOfThreads( NoOfThreads );
    DummyJob *dummies[ NoOfJobs];

    // ----- create a number of dummy jobs:
    for ( int count  = 0; count < NoOfJobs; ++count )
    {
        dummies[count] = new DummyJob (0, Multiplier * (count % 10) );
    }

    // ----- enqueue the jobs:
    for ( int count  = 0; count < NoOfJobs; ++count )
    {
        weaver.enqueue( dummies[count] );
    }

    weaver.finish();

    for ( int count  = 0; count < NoOfJobs; ++count )
    {
        delete dummies[count];
    }

    qDebug() << "main() exits here, the Weaver is destructed when it goes out"
             << " of scope " << endl
             << "... let's see if that works:" << endl;
    return 0;
}
Exemplo n.º 2
0
void JobTests::DequeSuspendedSequence()
{
    ThreadWeaver::Weaver weaver;
    weaver.suspend();
    weaver.enqueue(new ThreadWeaver::JobSequence(this) );
    weaver.dequeue();
    // don't crash
}
Exemplo n.º 3
0
void JobTests::WeaverLazyThreadCreationTest()
{
    ThreadWeaver::Weaver weaver;
    QString sequence;
    QCOMPARE (weaver.currentNumberOfThreads(), 0);
    AppendCharacterJob a( QChar('a'), &sequence, this);
    weaver.enqueue( & a);
    weaver.finish();
    QVERIFY(a.isFinished());
    QCOMPARE (weaver.currentNumberOfThreads(), 1);
}