File tree Expand file tree Collapse file tree 6 files changed +16
-8
lines changed Expand file tree Collapse file tree 6 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -133,7 +133,7 @@ ConcurrencyWorker::HandleNoConcurrency()
133133 wake_signal_.wait (lock, [this ]() {
134134 return exiting_ || (thread_config_->concurrency_ > 0 );
135135 });
136- // Stop executing if concurrency is 0 and early exit is requested
136+ // Stop executing if concurrency is 0 and we are exiting
137137 if (exiting_ && thread_config_->concurrency_ == 0 ) {
138138 return true ;
139139 }
@@ -181,7 +181,7 @@ ConcurrencyWorker::WaitForResponses()
181181 std::unique_lock<std::mutex> lk (cb_mtx_);
182182 thread_stat_->idle_timer .Start ();
183183 cb_cv_.wait (lk, [this ] {
184- if (notified_ || exiting_) {
184+ if (notified_ || ( exiting_ && fast_exit_) ) {
185185 notified_ = false ;
186186 return true ;
187187 }
Original file line number Diff line number Diff line change @@ -298,6 +298,9 @@ InferContext::AsyncCallbackFuncImpl(cb::InferResult* result)
298298 // Add the request record to thread request records vector with
299299 // proper locking
300300 std::lock_guard<std::mutex> lock (thread_stat_->mu_ );
301+
302+ // If we are fast exiting, do not handle the request and instead exit
303+ // immediately
301304 if (exiting_ && fast_exit_) {
302305 return ;
303306 }
Original file line number Diff line number Diff line change @@ -105,6 +105,9 @@ class InferContext {
105105 void Init ();
106106
107107 // Signal to the context to stop working and exit
108+ // If fast exit is true, everything should be immediately dropped
109+ // If fast exit is false, the context should still handle outstanding requests
110+ // before exiting
108111 void Exit (bool fast_exit)
109112 {
110113 exiting_ = true ;
Original file line number Diff line number Diff line change @@ -250,7 +250,6 @@ LoadManager::StopWorkerThreads()
250250{
251251 bool fast_exit = shared_memory_type_ == SharedMemoryType::NO_SHARED_MEMORY;
252252
253- // FIXME do I need to acquire the lock first?
254253 for (auto & worker : workers_) {
255254 worker->Exit (fast_exit);
256255 }
Original file line number Diff line number Diff line change @@ -41,8 +41,8 @@ LoadWorker::Exit(bool fast_exit)
4141 ctx->Exit (fast_exit);
4242 }
4343
44- exiting_ = true ;
4544 fast_exit_ = fast_exit;
45+ exiting_ = true ;
4646
4747 {
4848 std::lock_guard<std::mutex> lk (cb_mtx_);
@@ -68,9 +68,8 @@ LoadWorker::HandleExitConditions()
6868{
6969 if (ShouldExit ()) {
7070 CompleteOngoingSequences ();
71- if (!fast_exit_) {
72- WaitForOngoingRequests ();
73- }
71+ thread_stat_->idle_timer .Start ();
72+ WaitForOngoingRequests ();
7473 return true ;
7574 }
7675 return false ;
@@ -90,7 +89,7 @@ LoadWorker::CompleteOngoingSequences()
9089void
9190LoadWorker::WaitForOngoingRequests ()
9291{
93- while (GetNumOngoingRequests () != 0 && !fast_exit_) {
92+ while (GetNumOngoingRequests () != 0 && !(exiting_ && fast_exit_) ) {
9493 std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
9594 }
9695}
Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ class LoadWorker : public IWorker {
6969
7070 virtual ~LoadWorker () = default ;
7171
72+ // Tell the worker thread to stop issuing new requests and to exit
73+ // If fast_exit is true, the worker thread should exit as fast as possible. If
74+ // it is false, it should still wait for all outstanding requests before
75+ // exiting
7276 virtual void Exit (bool fast_exit) override ;
7377
7478 protected:
You can’t perform that action at this time.
0 commit comments