18.1 General

18.1.1 Do not use platform specific multi-threading facilities

Rather than using platform-specific facilities, the C++ standard library should be used as it is platform independent.

 // @@- Non-Compliant -@@
#include <pthread.h>
void* thread1(void*);
void f1()
{
pthread_t t1;
pthread_create(&t1, nullptr, thread1, 0);
// ...
}
     
// @@+ Compliant +@@
#include <thread>
void thread2();
void f2()
{
std::thread t1(thread2);
// ...
}

References

  • Williams Concurrency – 1.3.4
  • Use native handles to transcend the C++11 API Meyers Effective C++ ’11 (draft TOC)

Click here for references