Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Development/nmos/mutex.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef NMOS_MUTEX_H
#define NMOS_MUTEX_H

#include <condition_variable>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header should come from bst/shared_mutex.h and if there's a case where it should be but isn't, the fix belongs there, I think?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The <condition_variable> header only comes from bst/shared_mutex. h when BST_THREAD_BOOST is not defined. We have the BST_THREAD_BOOST set as the default in the build, i.e., we always use boost as the default.

we should include the for std::unique_lock instead of the <condition_variable>

#include "bst/shared_mutex.h"

namespace nmos
Expand Down
12 changes: 6 additions & 6 deletions Development/nmos/test/condition_variable_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "bst/test/test.h"

namespace
namespace test_condition_variable
{
struct test_model
{
Expand Down Expand Up @@ -89,27 +89,27 @@ namespace
////////////////////////////////////////////////////////////////////////////////////////////
BST_TEST_CASE(testConditionVariableWait)
{
const auto max_threads{ 500 };
const int max_threads{ 500 };

// start a wait thread
std::thread wait_thread(wait);
std::thread wait_thread(test_condition_variable::wait);

// start a large number of lock_then_unlock threads to exhaust the lock limit
std::vector<std::thread> threads;
for (auto idx = 0; idx < max_threads; idx++)
{
threads.push_back(std::thread(lock_then_unlock));
threads.push_back(std::thread(test_condition_variable::lock_then_unlock));
}

// send a lot of notifications to wake up the wait thread
// to wake the wait thread when lock limit is exhausted
for (auto idx = 0; idx < 100; idx++)
{
model.notify();
test_condition_variable::model.notify();
}

// start the thread to pause 1 second before signal a shutdown
std::thread shutdown_thread(shutdown, std::chrono::seconds{ 1 });
std::thread shutdown_thread(test_condition_variable::shutdown, std::chrono::seconds{ 1 });

shutdown_thread.join();
wait_thread.join();
Expand Down
Loading