@@ -151,13 +151,52 @@ static int veryVeryVerbose;
151
151
typedef void Element;
152
152
typedef bdlcc::FixedQueue<Element*> Obj;
153
153
154
+ const int k_DECISECOND = 100000 ; // microseconds in 0.1 seconds
155
+
154
156
// ============================================================================
155
157
// HELPER CLASSES AND FUNCTIONS FOR TESTING
156
158
// ----------------------------------------------------------------------------
157
159
158
160
namespace {
159
161
namespace u {
160
162
163
+ static bsls::AtomicInt s_continue;
164
+ static char s_watchdogText[128 ];
165
+
166
+ // / Assign the specified `value` to be displayed if the watchdog expires.
167
+ void setWatchdogText (const char *value)
168
+ {
169
+ memcpy (s_watchdogText, value, strlen (value) + 1 );
170
+ }
171
+
172
+ // / Watchdog function used to determine when a timeout should occur. This
173
+ // / function returns without expiration if `0 == s_continue` before one
174
+ // / second elapses. Upon expiration, `s_watchdogText` is displayed and the
175
+ // / program is aborted.
176
+ extern " C" void *watchdog (void *arg)
177
+ {
178
+ if (arg) {
179
+ setWatchdogText (static_cast <const char *>(arg));
180
+ }
181
+
182
+ const int MAX = 300 ; // one iteration is a deci-second
183
+
184
+ int count = 0 ;
185
+
186
+ while (s_continue) {
187
+ bslmt::ThreadUtil::microSleep (k_DECISECOND);
188
+ ++count;
189
+
190
+ ASSERTV (s_watchdogText, count < MAX);
191
+
192
+ if (MAX == count && s_continue) {
193
+ abort ();
194
+ }
195
+ }
196
+
197
+ return 0 ;
198
+ }
199
+
161
200
// / Return the current time, as a `TimeInterval`.
162
201
bsls::TimeInterval now ()
163
202
{
@@ -2348,6 +2387,12 @@ int main(int argc, char *argv[])
2348
2387
<< " ABA \" empty\" value test" << endl
2349
2388
<< " ======================" << endl;
2350
2389
2390
+ bslmt::ThreadUtil::Handle watchdogHandle;
2391
+
2392
+ ::u::s_continue = 1 ;
2393
+ ::u::setWatchdogText (" ABA 'empty' test" );
2394
+ bslmt::ThreadUtil::create (&watchdogHandle, ::u::watchdog, 0 );
2395
+
2351
2396
enum {
2352
2397
k_NUM_PUSHER_THREADS = 40 ,
2353
2398
k_NUM_VALUES = 6 ,
@@ -2398,8 +2443,12 @@ int main(int argc, char *argv[])
2398
2443
}
2399
2444
ASSERT (0 < ta.numAllocations ());
2400
2445
ASSERT (0 == ta.numBytesInUse ());
2401
- } break ;
2402
2446
2447
+ ::u::s_continue = 0 ;
2448
+
2449
+ ::u::setWatchdogText (" ABA 'empty' test: join watchdog" );
2450
+ bslmt::ThreadUtil::join (watchdogHandle);
2451
+ } break ;
2403
2452
case 6 : {
2404
2453
// --------------------------------------------------------------------
2405
2454
// CONCERN: REMOVE_ALL
0 commit comments