In c++ if I write a program using pthreads (using cmake as my build system and assuming I'm on a unix based system like OS X or Redhat), what is the difference between using pthread.h:
#include <iostream>
#include <pthread.h>
using namespace std;
void* print_message(void*) {
cout << "Threading\n";
}
int main() {
pthread_t t1;
pthread_create(&t1, NULL, &print_message, NULL);
return 0;
}
and using std::thread with a pthread compile flag:
#include <iostream>
#include <thread>
using namespace std;
void print_message() {
cout << "Threading\n";
}
int main() {
std::thread t1(&print_message);
t1.join();
return 0;
}
with the flags:
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(my_app Threads::Threads)