Why should the return type be of type (void *) for stream processing in C?

In c, we create a stream like this:

void * run(void * arg){
    printf("hello world\n");
}

int main(){
    pthread_t thread;
    int a = pthread_create(&thread, NULL, run, (void*)0);
}

But this will not work if I declare the launch as

void run(){}

On the other hand, if I pass it in (void *)in the parameter pthread_create, it works fine. Therefore, it accepts only functions with return types (void *).

Why?

Thank!

+3
source share
3 answers

My system man pthread_createsays:

If start_routinereturned, the effect will be as if there was an implicit call pthread_exit(), using the return value start_routineas the exit status.

This return value is available using the function pthread_join():

pthread_join() non-NULL value_ptr , pthread_exit() , , value_ptr.

+4

​​ void *, , pthread_join() .

-, return 0;.

+4

? - , . , , , , , . . , , . C *, , - .

0

All Articles