CodingHanYa / workspace

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

firma2021 opened this issue · comments

commented

类似于

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();
        }
    }
};

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

commented

好的!