From: Christopher Dykes Date: Tue, 19 Sep 2017 02:02:08 +0000 (-0700) Subject: Set names in NamedThreadFactory in the new thread X-Git-Tag: v2017.09.25.00~9 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=aa62e6f3ba01d7332f92ffe91694a43577234d62;p=folly.git Set names in NamedThreadFactory in the new thread Summary: This makes it now both work, and compile, on Windows. Reviewed By: yfeldblum Differential Revision: D5811100 fbshipit-source-id: 5d6bfc04ed8e60417615da15bd197769e0c79c11 --- diff --git a/folly/executors/NamedThreadFactory.h b/folly/executors/NamedThreadFactory.h index bcd4a6bb..856a5295 100644 --- a/folly/executors/NamedThreadFactory.h +++ b/folly/executors/NamedThreadFactory.h @@ -33,10 +33,12 @@ class NamedThreadFactory : public ThreadFactory { : prefix_(prefix.str()), suffix_(0) {} std::thread newThread(Func&& func) override { - auto thread = std::thread(std::move(func)); - folly::setThreadName( - thread.native_handle(), folly::to(prefix_, suffix_++)); - return thread; + auto name = folly::to(prefix_, suffix_++); + return std::thread( + [ func = std::move(func), name = std::move(name) ]() mutable { + folly::setThreadName(name); + func(); + }); } void setNamePrefix(folly::StringPiece prefix) {