Thread

以下會介紹如何使用 C++ 的 library,透過 RAII 的方式去操作 thread。


使用std::thread取代pthread

TODO: example


如果要 join thread,考慮使用gsl::joining_thread

Example
void f() { std::cout << "Hello "; }

void bad()
{
    std::thread thread{f};

    thread.join()            // Bad, 可能沒有join
}

void good()
{
    gsl::joining_thread thread{f};

} // Good, 自動 join

Reference

results matching ""

    No results matching ""