text
stringlengths 0
2.2M
|
---|
JobQueue::Job cjob =
|
bdlf::BindUtil::bind(&bsls::AtomicInt::add, &cCheck, 1);
|
importantQueue.processJob(ijob);
|
importantQueue.processJob(ijob);
|
importantQueue.processJob(ijob);
|
importantQueue.processJob(ijob);
|
importantQueue.processJob(ijob);
|
importantQueue.processJob(ijob);
|
urgentQueue.processJob(ujob);
|
urgentQueue.processJob(ujob);
|
urgentQueue.processJob(ujob);
|
urgentQueue.processJob(ujob);
|
criticalQueue.processJob(cjob);
|
criticalQueue.processJob(cjob);
|
tp.stop();
|
ASSERT(6 == iCheck);
|
ASSERT(4 == uCheck);
|
ASSERT(2 == cCheck);
|
return 0;
|
}
|
} // close namespace TEST_CASE_USAGE_EXAMPLE
|
// ============================================================================
|
// MAIN PROGRAM
|
// ----------------------------------------------------------------------------
|
int main(int argc, char *argv[])
|
{
|
int test = (argc > 1) ? bsl::atoi(argv[1]) : 1;
|
verbose = (argc > 2);
|
veryVerbose = (argc > 3);
|
veryVeryVerbose = (argc > 4);
|
veryVeryVeryVerbose = (argc > 5);
|
cout << "TEST " << __FILE__ << " CASE " << test << endl;
|
switch (test) { case 0:
|
case 6: {
|
// --------------------------------------------------------------------
|
// CONCERN: Single-processor multiplexor
|
//
|
// Concern:
|
// That a multiplexor shared between several threads and having
|
// a processor limit of 1 will process jobs correctly.
|
//
|
// Plan:
|
// Set up multiple threads sharing a single multiplexor. Set up the
|
// multiplexor with a limit of 1 processor. Ensure that a counter
|
// variable is hit the proper number of times.
|
//
|
// Testing:
|
// processJob();
|
// --------------------------------------------------------------------
|
if (verbose) cout << "Single-Processor Test" << endl
|
<< "=====================" << endl;
|
bslma::TestAllocator ta(veryVeryVeryVerbose);
|
{
|
using namespace TEST_CASE_6;
|
enum {
|
NUM_THREADS = 7,
|
MAX_QUEUESIZE = 1000,
|
NUM_JOBS = 100
|
};
|
bsls::AtomicInt timesCalled;
|
bslmt::Semaphore startSemaphore;
|
bdlmt::ThreadMultiplexor mX(1, MAX_QUEUESIZE, &ta);
|
bslmt::ThreadGroup threads;
|
bsl::function<void()> addFunc =
|
bdlf::BindUtil::bind(&bsls::AtomicInt::add, ×Called, 1);
|
for (int i = 0; i < NUM_THREADS; ++i) {
|
LOOP_ASSERT(i, 0 == threads.addThread(bdlf::BindUtil::bind(
|
&testCase6,
|
&startSemaphore,
|
&mX,
|
(int)NUM_JOBS,
|
addFunc)));
|
}
|
startSemaphore.post(NUM_THREADS);
|
threads.joinAll();
|
ASSERT(NUM_THREADS * NUM_JOBS == timesCalled);
|
}
|
ASSERT(0 < ta.numAllocations());
|
ASSERT(0 == ta.numBytesInUse());
|
} break;
|
case 5: {
|
// --------------------------------------------------------------------
|