Skip to content

Commit 52126b2

Browse files
committed
Fix duration timer shutdown
1 parent bbe0b60 commit 52126b2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

samples/kvssink_intermittent_sample.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ std::atomic<bool> terminated(FALSE);
3232
std::condition_variable cv;
3333
std::mutex cv_mutex;
3434

35+
std::condition_variable duration_cv;
36+
std::mutex duration_cv_mutex;
37+
3538
typedef enum _StreamSource {
3639
TEST_SOURCE,
3740
DEVICE_SOURCE
@@ -47,6 +50,7 @@ typedef struct _CustomData {
4750
} CustomData;
4851

4952
void shutdown_sample () {
53+
LOG_INFO("[KVS sample] Shutting down sample...");
5054
std::lock_guard<std::mutex> lock(cv_mutex);
5155
terminated = TRUE;
5256
cv.notify_all();
@@ -367,8 +371,8 @@ int main(int argc, char *argv[]) {
367371
// Start the timer thread to terminate the sample after a specified duration.
368372
std::thread timerThread([runtime_duration_seconds]() {
369373
LOG_INFO("[KVS sample] Timer thread started. Will wait for " << runtime_duration_seconds << " seconds or until terminated.");
370-
std::unique_lock<std::mutex> lck(cv_mutex);
371-
if (cv.wait_for(lck, std::chrono::seconds(runtime_duration_seconds)) == std::cv_status::timeout) {
374+
std::unique_lock<std::mutex> lck(duration_cv_mutex);
375+
if (duration_cv.wait_for(lck, std::chrono::seconds(runtime_duration_seconds)) == std::cv_status::timeout) {
372376
if (!terminated) {
373377
LOG_INFO("[KVS sample] Reached maximum runtime of " << runtime_duration_seconds << " seconds. Terminating.");
374378
shutdown_sample();

0 commit comments

Comments
 (0)