Skip to content

Commit

Permalink
add watchdog to case 7 (#5178)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Mendelsohn authored and GitHub Enterprise committed Jan 23, 2025
1 parent e39ba50 commit cded187
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion groups/bdl/bdlcc/bdlcc_fixedqueue.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,52 @@ static int veryVeryVerbose;
typedef void Element;
typedef bdlcc::FixedQueue<Element*> Obj;

const int k_DECISECOND = 100000; // microseconds in 0.1 seconds

// ============================================================================
// HELPER CLASSES AND FUNCTIONS FOR TESTING
// ----------------------------------------------------------------------------

namespace {
namespace u {

static bsls::AtomicInt s_continue;
static char s_watchdogText[128];

/// Assign the specified `value` to be displayed if the watchdog expires.
void setWatchdogText(const char *value)
{
memcpy(s_watchdogText, value, strlen(value) + 1);
}

/// Watchdog function used to determine when a timeout should occur. This
/// function returns without expiration if `0 == s_continue` before one
/// second elapses. Upon expiration, `s_watchdogText` is displayed and the
/// program is aborted.
extern "C" void *watchdog(void *arg)
{
if (arg) {
setWatchdogText(static_cast<const char *>(arg));
}

const int MAX = 300; // one iteration is a deci-second

int count = 0;

while (s_continue) {
bslmt::ThreadUtil::microSleep(k_DECISECOND);
++count;

ASSERTV(s_watchdogText, count < MAX);

if (MAX == count && s_continue) {
abort();
}
}

return 0;
}

/// Return the current time, as a `TimeInterval`.
bsls::TimeInterval now()
{
Expand Down Expand Up @@ -2348,6 +2387,12 @@ int main(int argc, char *argv[])
<< "ABA \"empty\" value test" << endl
<< "======================" << endl;

bslmt::ThreadUtil::Handle watchdogHandle;

::u::s_continue = 1;
::u::setWatchdogText("ABA 'empty' test");
bslmt::ThreadUtil::create(&watchdogHandle, ::u::watchdog, 0);

enum {
k_NUM_PUSHER_THREADS = 40,
k_NUM_VALUES = 6,
Expand Down Expand Up @@ -2398,8 +2443,12 @@ int main(int argc, char *argv[])
}
ASSERT(0 < ta.numAllocations());
ASSERT(0 == ta.numBytesInUse());
} break;

::u::s_continue = 0;

::u::setWatchdogText("ABA 'empty' test: join watchdog");
bslmt::ThreadUtil::join(watchdogHandle);
} break;
case 6: {
// --------------------------------------------------------------------
// CONCERN: REMOVE_ALL
Expand Down

0 comments on commit cded187

Please sign in to comment.