Skip to content

Commit c2b81b8

Browse files
committed
Used std::thread instead of std::jthread which is not supported in MacOS
1 parent bb3e839 commit c2b81b8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/api/MainSolver.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class MainSolver::TimeLimitImpl {
4545
private:
4646
MainSolver & solver;
4747

48-
std::jthread thread{};
48+
// not using std::jthread since MacOS does not support it
49+
std::thread thread{};
4950

5051
// See https://en.cppreference.com/w/cpp/thread/condition_variable.html
5152
std::mutex mtx{};
@@ -638,7 +639,7 @@ MainSolver::TimeLimitImpl::~TimeLimitImpl() {
638639
if (not isRunning()) { return; }
639640

640641
requestEnd();
641-
// no need to wait in destructor (thanks to std::jthread)
642+
waitToEnd();
642643
}
643644

644645
void MainSolver::TimeLimitImpl::setLimit(std::chrono::milliseconds limit) {
@@ -650,14 +651,14 @@ void MainSolver::TimeLimitImpl::setLimit(std::chrono::milliseconds limit) {
650651
waitToEnd();
651652
}
652653

653-
thread = std::jthread([this, limit] {
654+
thread = decltype(thread){[this, limit] {
654655
std::unique_lock lock(mtx);
655656
// Abort if a further future end request has already been sent
656657
if (endReq) { return; }
657658
// Releases the lock and suspends the thread, waiting on a notification or timeout
658659
// Notification must be sent *after* the wait, otherwise could be missed - hence checking `endReq` above
659660
if (condVar.wait_for(lock, limit) == std::cv_status::timeout) { solver.notifyStop(); }
660-
});
661+
}};
661662
}
662663

663664
void MainSolver::TimeLimitImpl::setLimitIfNotRunning(std::chrono::milliseconds limit) {

0 commit comments

Comments
 (0)