diff --git a/amtl/am-thread.h b/amtl/am-thread.h index 7f3f71d..029627a 100644 --- a/amtl/am-thread.h +++ b/amtl/am-thread.h @@ -101,12 +101,12 @@ static inline void SetThreadName(std::thread* thread, const char* name) { template static inline std::unique_ptr NewThread(const char* name, Function&& f, Args&&... args) { - auto callback = std::bind(std::forward(f), std::forward(args)...); - auto fn = [](const std::string& name, decltype(callback)&& callback) -> void { - SetThreadName(name.c_str()); - callback(); - }; - return std::make_unique(std::move(fn), std::string(name), std::move(callback)); + return std::make_unique( + [name, fn = std::forward(f), tup = std::make_tuple(std::forward(args)...)]() mutable { + SetThreadName(name); + std::apply(std::move(fn), std::move(tup)); + } + ); } } // namespace ke