text
stringlengths
0
2.2M
if (verbose && UQUEUE_MAX_PROC != uChecker.maxProcessors()) {
cout << "MILD WARNING: uChecker.maxProcessors() == "
<< uChecker.maxProcessors() << ", expected "
<< UQUEUE_MAX_PROC << endl;
}
LOOP_ASSERT(oChecker.maxProcessors(),
OQUEUE_MAX_PROC == oChecker.maxProcessors());
}
ASSERT(0 < ta.numAllocations());
ASSERT(0 == ta.numBytesInUse());
} break;
case 4: {
// --------------------------------------------------------------------
// CONCERN: Small number of threads test
//
// Concerns:
// Test the behavior of the component when the number of threads is
// smaller than the number of processors.
//
// Plan:
// Create a thread pool with 3 threads and a large queue. Using
// a multiplexor configured for 10 processors, submit many jobs
// and confirm they all run.
//
// Testing:
// processJob();
// --------------------------------------------------------------------
if (verbose) cout << "FEW THREADS TEST" << endl
<< "================" << endl;
bslma::TestAllocator ta(veryVeryVeryVerbose);
{
enum {
NUM_THREADS = 3, // total number of threads
MAX_QUEUESIZE = 6000,// total number of pending jobs
NUM_JOBS = 2000,// number of jobs to submit
MAX_PROC = 10 // test condition
};
bdlmt::FixedThreadPool tp(NUM_THREADS, MAX_QUEUESIZE, &ta);
if (0 != tp.start()) {
ASSERT(!"Could not start thread pool! "
"Threads cannot be created!");
break;
}
if (veryVerbose) cout << "Thread-pool Started" << endl;
TestQueue theQueue(10, MAX_QUEUESIZE, &tp, &ta);
UsageTestChecker checker(theQueue.multiplexor());
bslmt::Semaphore startSemaphore;
checker.setSemaphore(&startSemaphore);
for (int i = 0; i < NUM_JOBS; ++i) {
LOOP_ASSERT(i, 0 == theQueue.processJob(checker));
}
startSemaphore.post(NUM_JOBS);
tp.stop();
if (veryVerbose) cout << "Thread-pool Stopped" << endl;
ASSERT(NUM_JOBS == checker.timesCalled());
ASSERT(MAX_PROC >= checker.maxProcessors());
if (verbose) {
P(checker.timesCalled());
P(checker.maxProcessors());
}
}
ASSERT(0 < ta.numAllocations());
ASSERT(0 == ta.numBytesInUse());
} break;
case 3: {
// --------------------------------------------------------------------
// 1-length Queue Test
//
// Concerns:
// Test the behavior of the component when the queue has a capacity
// of only 1.
//
// Plan:
// Test the component with 7 threads and a queue of 1.
//
// Testing:
// processJob();
// --------------------------------------------------------------------
if (verbose) cout << "SMALL QUEUE TEST" << endl
<< "================" << endl;
bslma::TestAllocator ta(veryVeryVeryVerbose);
{
enum {
NUM_THREADS = 7, // total number of threads
MAX_QUEUESIZE = 1,
NUM_QUEUES = 3,