C++11 std::threads vs posix threads

后端 未结 4 2008
广开言路
广开言路 2020-12-02 04:05

Why should I prefer one or another in practice? What are technical differences except that std::thread is a class?

4条回答
  •  臣服心动
    2020-12-02 04:37

    For me the deciding technical difference is the absence of signal handling primitives in std as opposed to pthreads. The inability to properly dictate signal handling in a Unix process using std alone is AFAIK a debilitating flaw in the use of std::thread as it bars one from setting up the bona fide multi-threaded signal handling pattern to process all signals in a dedicated thread and block them in the rest. You are forced to assume std::thread is implemented using pthreads and hope for the best when using pthread_sigmask. Handling signals properly is non-negotiable in Unix systems programming for the enterprise.

    As at 2016, std::thread is a toy; simple as that.

提交回复
热议问题