|
[
Permlink
| « Hide
]
Martin Sebor added a comment - 07/Sep/07 02:52 PM
Travis, can you take a look at this to see if we could implement it for 4.2 and avoid the test timeouts?
Tentatively scheduled for 4.2.
2007-09-10 Travis Vitek <vitek@roguewave.com> STDCXX-536 rw_timeout.h: New file declares timeout functions used by tests. opt_timeout.h: New file declares timeout functions used by the test suite driver. opt_timeout.cpp: New file defines timeout functions used by the test suite driver. driver.cpp (rw_vtest): setup new command line options, enable and disable alarm for timeout. 22.locale.messages.mt.cpp (thread_func): use timeout to let test threads exit early. I'm not convinced that this is actually a smart thing to do. Tests that would noramlly time out will now exit successfully. This is probably okay if there is only one part to the entire test, but that is not the case with any of the multithreaded tests that I've seen. If a test has three parts, and the first part times out, parts two and three won't execute, but it will appear that the test ran just fine. That, and the new code doesn't provide anything for a test that doesn't poll the rw_timeout_expired() function. So this code is only really useful for the multithreaded tests. If that is the case then maybe the functionality thould be isolated to just those tests. fixed patch to not use rw_note when timer expires because that function is not mt-safe.
Discussion on this issue can be found here
http://www.nabble.com/-jira--Created%3A-%28STDCXX-536%29-allow-thread-safety-tests-to-time-out-without-failing-tf4386314.html Now that 4.2.0 is released, set Affects Version(s) accordingly.
Set Severity to Usability and checked Patch Available.
I'm not sure where we left this issue. The discussion kind of petered out... Do we want the patch or not?
The patch is not ready for submission. I think we need to pick up discussion on this issue again.
Unchecked Patch Available since it's not ready.
We need to make some decisions here about how we want this to work. The options that I see are
Any other ideas or comments? Defer to 4.3 or later. I don't recall seeing any discussion on this issue, and that discussion is necessary before we start implementing anything.
Proposed patch allows each call to rw_thread_pool() to specify a soft timeout in seconds. A non-zero timeout will cause a timer to be started when pool threads are spawned. When the timer expires, a flag will be set. The user thread function will need to poll this flag periodically through the function rw_thread_timeout_expired(), and if it is true the thread should return as soon as is reasonably possible.
Please review and provide feedback. 2008-05-07 Travis Vitek <vitek@roguewave.com> STDCXX-536 * tests/include/rw_thread.h: Reduce C linkage to areas that actually need it, add typedef for thread function type. (rw_thread_pool): Add timeout parameter with default value. (rw_thread_pool_timeout_expired): New function declaration. * tests/src/thread.cpp: (_rw_timeout_handler): New function to respond to alarm signals and set timeout flag. (rw_thread_pool_timeout_expired): New function to query timeout status. (rw_thread_pool): Set alarm based on timeout value. * tests/localization/22.locale.codecvt.mt.cpp: Add timeout option with default value. Pass timeout to rw_thread_pool(). Poll rw_thread_pool_time_expired() in thread function and respond. Removed rw_ prefix used by test driver symbols. * tests/localization/22.locale.cons.mt.cpp: Ditto. * tests/localization/22.locale.ctype.mt.cpp: Ditto. * tests/localization/22.locale.globals.mt.cpp: Ditto. * tests/localization/22.locale.messages.mt.cpp: Ditto. * tests/localization/22.locale.money.get.mt.cpp: Ditto. * tests/localization/22.locale.money.put.mt.cpp: Ditto. * tests/localization/22.locale.moneypunct.mt.cpp: Ditto. * tests/localization/22.locale.num.get.mt.cpp: Ditto. * tests/localization/22.locale.num.put.mt.cpp: Ditto. * tests/localization/22.locale.numpunct.mt.cpp: Ditto. * tests/localization/22.locale.statics.mt.cpp: Ditto. * tests/localization/22.locale.time.get.mt.cpp: Ditto. * tests/localization/22.locale.time.put.mt.cpp: Ditto. One request: can you separate out changes that are unrelated to the timeout enhancement to make this patch easier to review?
Other than that, a few questions/concerns:
Okay, I submitted an initial patch to remove the rw_ prefix from test local option variables. See r654561
As for those issues...
Having the main thread sleep for the timeout period is not really a good solution. If the timeout is 60 seconds, but the threads complete in 5, the main thread would waste 55 seconds waiting for the timeout to expire. It also has the problem that it won't work with single threaded builds. I have considered several possible implementations, and I don't see many options that do everything we would like. The two big issues are single threaded builds and being able to use the timeout with threads that are not explicitly joined by the thread creation function. The second issue is not critical, but it seems a bit kludgey to not support timeouts consistently regardless of what parameters you pass to rw_thead_pool(). One option would be to pass some context data to the thread and let the thread decide if it is time to exit on its own. The context could include the 'drop dead time' for the thread and then the thread could check the current time against that. Unfortunately that moves more logic into thread_func and rw_thread_pool_timeout_expired(). Another option would be to build a timer queue and . This would require that the test library always be built with threads so that we could spawn a thread to service the timers. I was hoping there would be a way to wake up the sleeping thread when the threads were done but it doesn't look like Pthreads has a feature like that (pthreads_timed_join()?) I'm just a little nervous about the interactions between signals and threads (POSIX Signal Concepts
Anything using pthreads stuff will have portability issues [er, windows] that will have to be addressed. We'll also have to decide what to do for single threaded builds. If we don't link the thread library in single threaded builds then we'll have trouble using pthread_cond_timedwait().
Of the 9 pages of information about signals, what issues are you concerned about. Please be specific. I don't have any specific issues in mind that should cause problems in our case. It's possible that the alarm() solution will be perfectly safe in the limited set of situations that we have to worry about, even if it isn't robust enough to be completely general. But experience has taught me that programs that mix threads and signals do tend to run into unanticipated problems, often due to portability issues, so I'm simply trying to see if there's a better, more general alternative. If not I guess we'll just have to trust we'll be fine and not push it too far in the future (e.g., when we implement the C++ Multi-threading library
I agree with Martin's concerns on mixing threads and signals. I would suggest using a messaging framework; it would be safer but would require even more infrastructure. As a starter for resolving this issue however, we should try Travis' approach since it most likely better than the current paradigm.
Then this question remains... How does such messaging framework work in a single threaded build? Does the test function need to call some messaging_framework_update() type function to make sure that any messages get processed or do we use a thread inside the test library that dispatches messages?
The simplest and probably most portable solution is to just add some context data that tells the thread how long it should run [say a start and end time]. Then the thread_func would just check to see if the current time was outside that period and bail. Committed to 4.2.x in r655960
Resolving. If someone really wants to discuss using another method we should open another issue.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||