text
stringlengths
0
2.2M
// MAIN PROGRAM
// ----------------------------------------------------------------------------
int main(int argc, char *argv[])
{
int test = argc > 1 ? atoi(argv[1]) : 0;
int verbose = argc > 2;
cout << "TEST " << __FILE__ << " CASE " << test << endl;
switch (test) { case 0:
case 5: {
///Usage
///-----
// This section illustrates intended use of this component.
//
///Example 1: Demonstrate Accessing & Modifying the Default Thread Stack Size
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// In this example we demonstrate how to access both the platform's native and
// BCE configured default stack sizes, and then to set the default stack size
// used by BCE. Note that the value returned by 'defaultThreadStackSize' may
// be adjusted from that provided by the underlying operating system to reflect
// the actual amount of stack memory available to a created thread. For
// example, on Itanium platforms (HPUX) the value will be scaled down from the
// operating system supplied value to account for the extra stack space devoted
// to storing registers. Note that operations creating a thread should perform
// a similar inverse adjustment when configuring the new thread's stack size
// (see 'bslmt_threadutil').
//
// First, we examine the platform's native thread stack size:
//..
const int nativeDefault =
bslmt::Configuration::nativeDefaultThreadStackSize();
ASSERT(nativeDefault > 0);
//..
// Then, we verify that 'defaultThreadStackSize' is unset.
//..
ASSERT(bslmt::ThreadAttributes::e_UNSET_STACK_SIZE ==
bslmt::Configuration::defaultThreadStackSize());
//..
// Next, we define 'newDefaultStackSize' to some size other than the platform's
// native default stack size:
//..
const int newDefaultStackSize = nativeDefault * 2;
//..
// Now, we set the default size for BCE to the new size:
//..
bslmt::Configuration::setDefaultThreadStackSize(newDefaultStackSize);
//..
// Finally, we verify that BCE's default thread stack size has been set to the
// value we specified:
//..
ASSERT(bslmt::Configuration::defaultThreadStackSize() ==
newDefaultStackSize);
ASSERT(bslmt::Configuration::defaultThreadStackSize() != nativeDefault);
//..
} break;
case 4: {
// --------------------------------------------------------------------
// MULTIPLE CALLS YIELD SAME RESULT
//
// Concern:
// Some of these calls may cache their results. Make sure they are
// returning the same value when called multiple times.
//
// Plan:
// Call the routines multiple times and compare values.
// --------------------------------------------------------------------
if (verbose) cout << "MULTIPLE CALLS YIELD SAME RESULT\n"
"================================\n";
const int native = Obj::nativeDefaultThreadStackSize();
ASSERT(native > 0);
for (int i = 0; i < 10; ++i) {
ASSERT(native == Obj::nativeDefaultThreadStackSize());
ASSERT(bslmt::ThreadAttributes::e_UNSET_STACK_SIZE ==
Obj::defaultThreadStackSize());
}
const int setSize = native * 2;
Obj::setDefaultThreadStackSize(setSize);
for (int i = 0; i < 10; ++i) {
ASSERT(setSize == Obj::defaultThreadStackSize());
}
Obj::setDefaultThreadStackSize(native);
for (int i = 0; i < 10; ++i) {
ASSERT(native == Obj::defaultThreadStackSize());
}
} break;
case 3: {
// --------------------------------------------------------------------
// SETTING THE THREAD STACK SIZE / USAGE
//