Angel.King.47 Angel.King.47 - 2 months ago 28
C++ Question

Simple pthread! C++

I have no idea why this doesn't work

#include <iostream>
#include <pthread.h>
using namespace std;

void *print_message(){

cout << "Threading\n";
}



int main() {

pthread_t t1;

pthread_create(&t1, NULL, &print_message, NULL);
cout << "Hello";

return 0;
}


The error:


[Description, Resource, Path, Location, Type] initializing argument 3
of 'int pthread_create(pthread_t*, const pthread_attr_t*, void*
(*)(void*), void*)' threading.cpp threading/src line 24 C/C++
Problem

Answer

You should declare the thread main as:

void* print_message(void*) // takes one parameter, unnamed if you aren't using it
Comments