//C++ code that uses pthread functions // #include #include #include using namespace std; #if defined(__cplusplus) extern "C" #endif void *print_message(void* arg) { int value = *(static_cast(arg)); cout << "Threading " << value << endl; *(static_cast(arg)) = ++value; cout << "The value of arg is now " << *(static_cast(arg)) << endl; pthread_exit(arg); } int main() { pthread_t t1; int i = 13, *ip = &i; if( pthread_create(&t1, NULL, print_message, (static_cast(ip))) != 0) { cout << "Couldn't create the thread \n"; exit(1); } cout << "Hello" << endl; void* result = static_cast(ip); pthread_join(t1,&result); cout << "The return value was " << *(static_cast(result)) << endl; return 0; }