CodingHanYa / workspace

workspace是基于C++11的轻量级异步执行框架,支持:通用任务异步并发执行、优先级任务调度、自适应动态线程池、高效静态线程池、异常处理机制等。
Apache License 2.0
1.03k stars 152 forks source link

封装一个自动join()的RAII线程类是否能提高异常安全性,避免其它一些问题? #3

Closed firma2021 closed 1 year ago

firma2021 commented 1 year ago

类似于

class scoped_thread 
{
private:
    thread thread_;

public:
    template <typename... Arg>
    scoped_thread(Arg&&... arg)
    : thread_(std::forward<Arg>(arg)...)
    {}

    scoped_thread(scoped_thread&& other)
    : thread_(std::move(other.thread_))
    {}

    scoped_thread(const scoped_thread&) = delete;

    ~scoped_thread()
    {
        if (thread_.joinable()) 
        {
            thread_.join();
        }
    }
};
CodingHanYa commented 1 year ago

我觉得不错,你可以推一个分支进来哦,一起参与进来。

firma2021 commented 1 year ago

好的!