Skip to content

Commit

Permalink
Check if notifier thread is running before warning
Browse files Browse the repository at this point in the history
  • Loading branch information
pentschev committed Oct 18, 2024
1 parent 590e5b9 commit c609805
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cpp/include/ucxx/notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ class Notifier {
* it should stop and exit.
*/
virtual void stopRequestNotifierThread() = 0;

/**
* @brief Returns whether the thread is running.
*
* @returns Whether the thread is running.
*/
[[nodiscard]] virtual bool isRunning() const = 0;
};

} // namespace ucxx
5 changes: 5 additions & 0 deletions cpp/include/ucxx/worker_progress_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ class WorkerProgressThread {
*/
[[nodiscard]] std::thread::id getId() const;

/**
* @brief Returns whether the thread is running.
*
* @returns Whether the thread is running.
*/
[[nodiscard]] bool isRunning() const;

void stop();
Expand Down
7 changes: 7 additions & 0 deletions cpp/python/include/ucxx/python/notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ class Notifier : public ::ucxx::Notifier {
* that it should stop and exit.
*/
void stopRequestNotifierThread() override;

/**
* @brief Returns whether the thread is running.
*
* @returns Whether the thread is running.
*/
[[nodiscard]] bool isRunning() const override;
};

} // namespace python
Expand Down
6 changes: 6 additions & 0 deletions cpp/python/src/notifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ void Notifier::stopRequestNotifierThread()
_notifierThreadConditionVariable.notify_all();
}

bool Notifier::isRunning() const
{
return _notifierThreadFutureStatusReady ||
_notifierThreadFutureStatusFinished == RequestNotifierThreadState::Running;
}

} // namespace python

} // namespace ucxx
2 changes: 1 addition & 1 deletion cpp/src/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Worker::~Worker()
"unintended effects, such as destructor being called from that thread.");
stopProgressThreadNoWarn();
}
if (_notifier) {
if (_notifier && _notifier->isRunning()) {
ucxx_warn(
"The notifier thread should be explicitly stopped with `stopNotifierThread()` to prevent "
"unintended effects, such as destructor being called from that thread.");
Expand Down

0 comments on commit c609805

Please sign in to comment.