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()
133
133
wake_signal_.wait (lock, [this ]() {
134
134
return exiting_ || (thread_config_->concurrency_ > 0 );
135
135
});
136
- // Stop executing if concurrency is 0 and early exit is requested
136
+ // Stop executing if concurrency is 0 and we are exiting
137
137
if (exiting_ && thread_config_->concurrency_ == 0 ) {
138
138
return true ;
139
139
}
@@ -181,7 +181,7 @@ ConcurrencyWorker::WaitForResponses()
181
181
std::unique_lock<std::mutex> lk (cb_mtx_);
182
182
thread_stat_->idle_timer .Start ();
183
183
cb_cv_.wait (lk, [this ] {
184
- if (notified_ || exiting_) {
184
+ if (notified_ || ( exiting_ && fast_exit_) ) {
185
185
notified_ = false ;
186
186
return true ;
187
187
}
Original file line number Diff line number Diff line change @@ -298,6 +298,9 @@ InferContext::AsyncCallbackFuncImpl(cb::InferResult* result)
298
298
// Add the request record to thread request records vector with
299
299
// proper locking
300
300
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
301
304
if (exiting_ && fast_exit_) {
302
305
return ;
303
306
}
Original file line number Diff line number Diff line change @@ -105,6 +105,9 @@ class InferContext {
105
105
void Init ();
106
106
107
107
// 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
108
111
void Exit (bool fast_exit)
109
112
{
110
113
exiting_ = true ;
Original file line number Diff line number Diff line change @@ -250,7 +250,6 @@ LoadManager::StopWorkerThreads()
250
250
{
251
251
bool fast_exit = shared_memory_type_ == SharedMemoryType::NO_SHARED_MEMORY;
252
252
253
- // FIXME do I need to acquire the lock first?
254
253
for (auto & worker : workers_) {
255
254
worker->Exit (fast_exit);
256
255
}
Original file line number Diff line number Diff line change @@ -41,8 +41,8 @@ LoadWorker::Exit(bool fast_exit)
41
41
ctx->Exit (fast_exit);
42
42
}
43
43
44
- exiting_ = true ;
45
44
fast_exit_ = fast_exit;
45
+ exiting_ = true ;
46
46
47
47
{
48
48
std::lock_guard<std::mutex> lk (cb_mtx_);
@@ -68,9 +68,8 @@ LoadWorker::HandleExitConditions()
68
68
{
69
69
if (ShouldExit ()) {
70
70
CompleteOngoingSequences ();
71
- if (!fast_exit_) {
72
- WaitForOngoingRequests ();
73
- }
71
+ thread_stat_->idle_timer .Start ();
72
+ WaitForOngoingRequests ();
74
73
return true ;
75
74
}
76
75
return false ;
@@ -90,7 +89,7 @@ LoadWorker::CompleteOngoingSequences()
90
89
void
91
90
LoadWorker::WaitForOngoingRequests ()
92
91
{
93
- while (GetNumOngoingRequests () != 0 && !fast_exit_) {
92
+ while (GetNumOngoingRequests () != 0 && !(exiting_ && fast_exit_) ) {
94
93
std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
95
94
}
96
95
}
Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ class LoadWorker : public IWorker {
69
69
70
70
virtual ~LoadWorker () = default ;
71
71
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
72
76
virtual void Exit (bool fast_exit) override ;
73
77
74
78
protected:
You can’t perform that action at this time.
0 commit comments