Modified: stdcxx/branches/4.3.x/tests/localization/22.locale.time.get.mt.cpp URL: http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/tests/localization/22.locale.time.get.mt.cpp?rev=660350&r1=660349&r2=660350&view=diff ============================================================================== --- stdcxx/branches/4.3.x/tests/localization/22.locale.time.get.mt.cpp (original) +++ stdcxx/branches/4.3.x/tests/localization/22.locale.time.get.mt.cpp Mon May 26 18:51:19 2008 @@ -43,17 +43,20 @@ // default number of threads (will be adjusted to the number // of processors/cores later) -int rw_opt_nthreads = 1; +int opt_nthreads = 1; // the number of times each thread should iterate -int rw_opt_nloops = 50000; +int opt_nloops = 50000; // number of locales to use -int rw_opt_nlocales = MAX_THREADS; +int opt_nlocales = MAX_THREADS; // should all threads share the same set of locale objects instead // of creating their own? -int rw_opt_shared_locale; +int opt_shared_locale; + +// default timeout used by each threaded section of this test +int opt_timeout = 60; /**************************************************************************/ @@ -162,7 +165,10 @@ std::ios_base::iostate state = std::ios_base::goodbit; std::tm local; - for (int i = 0; i != rw_opt_nloops; ++i) { + for (int i = 0; i != opt_nloops; ++i) { + + if (rw_thread_pool_timeout_expired ()) + break; // save the name of the locale const MyTimeData& data = my_time_data [i % nlocales]; @@ -171,8 +177,8 @@ // facet from it and use it to format a random time value // using a random conversion specifier const std::locale loc = - rw_opt_shared_locale ? data.locale_ - : std::locale (data.locale_name_); + opt_shared_locale ? data.locale_ + : std::locale (data.locale_name_); if (test_char) { // exercise the narrow char specialization of the facet @@ -420,7 +426,7 @@ #endif // _RWSTD_NO_WCHAR_T - if (rw_opt_shared_locale) + if (opt_shared_locale) data.locale_ = loc; nlocales += 1; @@ -431,7 +437,7 @@ "failed to create locale(%#s)", name); } - if (nlocales == maxinx || nlocales == std::size_t (rw_opt_nlocales)) + if (nlocales == maxinx || nlocales == std::size_t (opt_nlocales)) break; } @@ -442,8 +448,8 @@ rw_info (0, 0, 0, "testing std::time_get<charT> with %d thread%{?}s%{;}, " "%d iteration%{?}s%{;} each, in %zu locales { %{ [EMAIL PROTECTED] }", - rw_opt_nthreads, 1 != rw_opt_nthreads, - rw_opt_nloops, 1 != rw_opt_nloops, + opt_nthreads, 1 != opt_nthreads, + opt_nloops, 1 != opt_nloops, nlocales, int (nlocales), "%#s", locales); rw_info (0, 0, 0, "exercising std::time_get<char>"); @@ -453,11 +459,12 @@ // create and start a pool of threads and wait for them to finish int result = - rw_thread_pool (0, std::size_t (rw_opt_nthreads), 0, thread_func, 0); + rw_thread_pool (0, std::size_t (opt_nthreads), 0, + thread_func, 0, std::size_t (opt_timeout)); rw_error (result == 0, 0, __LINE__, "rw_thread_pool(0, %d, 0, %{#f}, 0) failed", - rw_opt_nthreads, thread_func); + opt_nthreads, thread_func); #ifndef _RWSTD_NO_WCHAR_T @@ -468,11 +475,12 @@ // start a pool of threads to exercise wstring thread safety result = - rw_thread_pool (0, std::size_t (rw_opt_nthreads), 0, thread_func, 0); + rw_thread_pool (0, std::size_t (opt_nthreads), 0, + thread_func, 0, std::size_t (opt_timeout)); rw_error (result == 0, 0, __LINE__, "rw_thread_pool(0, %d, 0, %{#f}, 0) failed", - rw_opt_nthreads, thread_func); + opt_nthreads, thread_func); // exercise both the char and the wchar_t specializations // at the same time @@ -485,11 +493,12 @@ // start a pool of threads to exercise wstring thread safety result = - rw_thread_pool (0, std::size_t (rw_opt_nthreads), 0, thread_func, 0); + rw_thread_pool (0, std::size_t (opt_nthreads), 0, + thread_func, 0, std::size_t (opt_timeout)); rw_error (result == 0, 0, __LINE__, "rw_thread_pool(0, %d, 0, %{#f}, 0) failed", - rw_opt_nthreads, thread_func); + opt_nthreads, thread_func); #endif // _RWSTD_NO_WCHAR_T @@ -504,24 +513,26 @@ // set nthreads to the greater of the number of processors // and 2 (for uniprocessor systems) by default - rw_opt_nthreads = rw_get_cpus (); - if (rw_opt_nthreads < 2) - rw_opt_nthreads = 2; + opt_nthreads = rw_get_cpus (); + if (opt_nthreads < 2) + opt_nthreads = 2; #endif // _RWSTD_REENTRANT return rw_test (argc, argv, __FILE__, "lib.locale.time.get", "thread safety", run_test, + "|-soft-timeout#0 " // must be non-negative "|-nloops#0 " // must be non-negative "|-nthreads#0-* " // must be in [0, MAX_THREADS] "|-nlocales#0 " // arg must be non-negative "|-locales= " // must be provided "|-shared-locale# ", - &rw_opt_nloops, + &opt_timeout, + &opt_nloops, int (MAX_THREADS), - &rw_opt_nthreads, - &rw_opt_nlocales, + &opt_nthreads, + &opt_nlocales, &rw_opt_setlocales, - &rw_opt_shared_locale); + &opt_shared_locale); }
Modified: stdcxx/branches/4.3.x/tests/localization/22.locale.time.put.mt.cpp URL: http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/tests/localization/22.locale.time.put.mt.cpp?rev=660350&r1=660349&r2=660350&view=diff ============================================================================== --- stdcxx/branches/4.3.x/tests/localization/22.locale.time.put.mt.cpp (original) +++ stdcxx/branches/4.3.x/tests/localization/22.locale.time.put.mt.cpp Mon May 26 18:51:19 2008 @@ -67,6 +67,9 @@ // of creating their own? int opt_shared_locale; +// default timeout used by each threaded section of this test +int opt_timeout = 60; + /**************************************************************************/ // array of locale names to use for testing @@ -157,6 +160,9 @@ for (int i = 0; i != opt_nloops; ++i) { + if (rw_thread_pool_timeout_expired ()) + break; + // save the name of the locale const MyTimeData& data = my_time_data [i % nlocales]; @@ -165,7 +171,7 @@ // using a random conversion specifier const std::locale loc = opt_shared_locale ? data.locale_ - : std::locale (data.locale_name_); + : std::locale (data.locale_name_); if (test_char) { // exercise the narrow char specialization of the facet @@ -331,7 +337,8 @@ // create and start a pool of threads and wait for them to finish int result = - rw_thread_pool (0, std::size_t (opt_nthreads), 0, thread_func, 0); + rw_thread_pool (0, std::size_t (opt_nthreads), 0, + thread_func, 0, std::size_t (opt_timeout)); rw_error (result == 0, 0, __LINE__, "rw_thread_pool(0, %d, 0, %{#f}, 0) failed", @@ -346,7 +353,8 @@ // start a pool of threads to exercise wstring thread safety result = - rw_thread_pool (0, std::size_t (opt_nthreads), 0, thread_func, 0); + rw_thread_pool (0, std::size_t (opt_nthreads), 0, + thread_func, 0, std::size_t (opt_timeout)); rw_error (result == 0, 0, __LINE__, "rw_thread_pool(0, %d, 0, %{#f}, 0) failed", @@ -363,7 +371,8 @@ // start a pool of threads to exercise wstring thread safety result = - rw_thread_pool (0, std::size_t (opt_nthreads), 0, thread_func, 0); + rw_thread_pool (0, std::size_t (opt_nthreads), 0, + thread_func, 0, std::size_t (opt_timeout)); rw_error (result == 0, 0, __LINE__, "rw_thread_pool(0, %d, 0, %{#f}, 0) failed", @@ -391,11 +400,13 @@ return rw_test (argc, argv, __FILE__, "lib.locale.time.put", "thread safety", run_test, + "|-soft-timeout#0 " // must be non-negative "|-nloops#0 " // must be non-negative "|-nthreads#0-* " // must be in [0, MAX_THREADS] "|-nlocales#0 " // arg must be non-negative "|-locales= " // must be provided "|-shared-locale# ", + &opt_timeout, &opt_nloops, int (MAX_THREADS), &opt_nthreads, Modified: stdcxx/branches/4.3.x/tests/src/thread.cpp URL: http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/tests/src/thread.cpp?rev=660350&r1=660349&r2=660350&view=diff ============================================================================== --- stdcxx/branches/4.3.x/tests/src/thread.cpp (original) +++ stdcxx/branches/4.3.x/tests/src/thread.cpp Mon May 26 18:51:19 2008 @@ -30,6 +30,7 @@ #define _RWSTD_TEST_SRC #include <rw_thread.h> +#include <rw_alarm.h> // for rw_alarm() #include <stddef.h> // for size_t #include <string.h> // for memset() @@ -52,16 +53,41 @@ static long maxthreads; +/************************************************************************/ -#if defined (_RWSTD_POSIX_THREADS) -# include <pthread.h> +static volatile int +_rw_timeout_expired = 0; + +/************************************************************************/ + +_TEST_EXPORT int +rw_thread_pool_timeout_expired () +{ + return _rw_timeout_expired != 0; +} + +/************************************************************************/ extern "C" { +static void +_rw_timeout_handler (int) +{ + _rw_timeout_expired = 1; +} + +} // extern "C" + +/************************************************************************/ + + +#if defined (_RWSTD_POSIX_THREADS) +# include <pthread.h> + _TEST_EXPORT int rw_thread_create (rw_thread_t *thr_id, rw_thread_attr_t*, - void* (*thr_proc)(void*), + rw_thread_proc *thr_proc, void *thr_arg) { #ifdef _RWSTD_OS_SUNOS @@ -109,19 +135,15 @@ return result; } -} // extern "C" - /**************************************************************************/ #elif defined (_RWSTD_SOLARIS_THREADS) # include <thread.h> -extern "C" { - _TEST_EXPORT int rw_thread_create (rw_thread_t *thr_id, rw_thread_attr_t*, - void* (*thr_proc)(void*), + rw_thread_proc *thr_proc, void *thr_arg) { static int concurrency_set; @@ -170,8 +192,6 @@ return result; } -} // extern "C" - /**************************************************************************/ #elif defined (_RWSTD_DEC_THREADS) @@ -179,13 +199,10 @@ # include <setjmp.h> # include <cma.h> - -extern "C" { - _TEST_EXPORT int rw_thread_create (rw_thread_t *thr_id, rw_thread_attr_t*, - void* (*thr_proc)(void*), + rw_thread_proc *thr_proc, void *thr_arg) { rw_thread_t tmpid; @@ -244,19 +261,15 @@ return status; } -} // extern "C" - /**************************************************************************/ #elif defined (_WIN32) && defined (_MT) # include <process.h> // for _beginthreadex() -extern "C" { - _TEST_EXPORT int rw_thread_create (rw_thread_t *thr_id, rw_thread_attr_t*, - void* (*thr_proc)(void*), + rw_thread_proc *thr_proc, void *thr_arg) { int result = 0; @@ -324,8 +337,6 @@ return result; } -} // extern "C" - /**************************************************************************/ #else // unknown/missing threads environment @@ -352,12 +363,10 @@ # endif # endif // ENOTSUP -extern "C" { - _TEST_EXPORT int rw_thread_create (rw_thread_t*, rw_thread_attr_t*, - void* (*)(void*), + rw_thread_proc*, void*) { _RWSTD_UNUSED (maxthreads); @@ -372,8 +381,6 @@ return ENOTSUP; } -} // extern "C" - #endif // threads environment /**************************************************************************/ @@ -471,16 +478,20 @@ /**************************************************************************/ -extern "C" { - - _TEST_EXPORT int rw_thread_pool (rw_thread_t *thr_id, size_t nthrs, rw_thread_attr_t*, - void* (*thr_proc)(void*), - void* *thr_arg) -{ + rw_thread_proc *thr_proc, + void* *thr_arg, + size_t timeout) +{ + // apply timeout if one was specified + if (0 != timeout) { + _rw_timeout_expired = 0; + rw_alarm (timeout, _rw_timeout_handler); + } + // small buffer for thread ids when invoked with (thr_id == 0) rw_thread_t id_buf [16]; @@ -575,5 +586,3 @@ return 0; } - -} // extern "C"
