text
stringlengths 0
2.2M
|
---|
//
|
// Concerns:
|
// To test behavior and performance in case of many threads
|
// and many QLocks.
|
//
|
// Plan:
|
// Create array of data slots. Each element-slot is protected by
|
// its own QLock. Create multiple threads. Each thread in the loop
|
// obtains a lock for the random slot. Upon acquiring the lock for
|
// the slot, the thread stores locally the slot data, manipulates
|
// them with slot data, ensures the slot data is not modified by
|
// other threads, restores the original slot data, and releases
|
// the slot lock. Repeat above action in the loop.
|
//
|
// Repeat above scenario several times, incrementing the number of
|
// threads by one on each iteration.
|
// --------------------------------------------------------------------
|
enum {
|
k_MAX_SLOTS = 1000,
|
k_MAX_ITER = 100000,
|
k_MAX_THREADS = 20
|
};
|
{
|
bsls::Stopwatch sw;
|
sw.start();
|
CaseData5 data;
|
MyTask task51(testCase5_fn1, &data);
|
for (int i=1; i < k_MAX_THREADS; ++i) {
|
data.d_numIter = k_MAX_ITER;
|
data.d_numElements = k_MAX_SLOTS;
|
data.d_mutexes = 0;
|
data.d_qlocks = new bslmt::QLock [k_MAX_SLOTS];
|
data.d_slots = new int [k_MAX_SLOTS];
|
for (int j=0; j < k_MAX_SLOTS; ++j) {
|
data.d_slots[j] = 0;
|
data.d_qlocks[j].initialize();
|
}
|
bslmt::ThreadUtil::yield();
|
ASSERT(0 == task51.start(i));
|
ASSERT(0 == task51.stop());
|
if (veryVerbose) {
|
bsl::cout << i << bsl::endl << bsl::flush;
|
}
|
delete [] data.d_qlocks;
|
delete [] data.d_slots;
|
}
|
sw.stop();
|
if (verbose) printMetrics(bsl::cout, "QLock", k_MAX_THREADS, sw);
|
}
|
{
|
bsls::Stopwatch sw;
|
sw.start();
|
CaseData5 data;
|
MyTask task52(testCase5_fn2, &data);
|
for (int i=1; i < k_MAX_THREADS; ++i) {
|
data.d_numIter = k_MAX_ITER;
|
data.d_numElements = k_MAX_SLOTS;
|
data.d_qlocks = 0;
|
data.d_mutexes = new bslmt::Mutex [k_MAX_SLOTS];
|
data.d_slots = new int [k_MAX_SLOTS];
|
for (int j=0; j < k_MAX_SLOTS; ++j) {
|
data.d_slots[j] = 0;
|
}
|
ASSERT(0 == task52.start(i));
|
ASSERT(0 == task52.stop());
|
delete [] data.d_mutexes;
|
delete [] data.d_slots;
|
}
|
sw.stop();
|
if (verbose) printMetrics(bsl::cout, "Mutex", k_MAX_THREADS, sw);
|
}
|
} break;
|
case 4: {
|
// --------------------------------------------------------------------
|
// Set/Wait Flags Test
|
//
|
// Concerns:
|
// To test internal primitives setFlags/waitOnFlag on which QLock
|
// is based.
|
//
|
// Plan:
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.