Skip to content

Commit

Permalink
Always set a thread name in FunctionScheduler
Browse files Browse the repository at this point in the history
Summary:
The name for the scheduling thread is specified with `FunctionScheduler::setThreadName`, which is not always called (or may even be called too late!), in which case the thread name is inherited from thread that calls `start()`, leading to confusing attribution.

Use a default name instead, as we do in several other executor-like primitives.

Reviewed By: philippv, luciang

Differential Revision: D40797728

fbshipit-source-id: 2e3d2516b0dc2fd07b6c2783de30797c8c2d2f43
  • Loading branch information
ot authored and facebook-github-bot committed Oct 28, 2022
1 parent 24e95d1 commit 3e98846
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions folly/experimental/FunctionScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,7 @@ bool FunctionScheduler::shutdown() {
void FunctionScheduler::run() {
std::unique_lock<std::mutex> lock(mutex_);

if (!threadName_.empty()) {
folly::setThreadName(threadName_);
}
folly::setThreadName(threadName_);

while (running_) {
// If we have nothing to run, wait until a function is added or until we
Expand Down
2 changes: 1 addition & 1 deletion folly/experimental/FunctionScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class FunctionScheduler {
// or when the FunctionScheduler is stopped.
std::condition_variable runningCondvar_;

std::string threadName_;
std::string threadName_{"FuncSched"};
bool steady_{false};
bool cancellingCurrentFunction_{false};
};
Expand Down

0 comments on commit 3e98846

Please sign in to comment.