I have seen the documentation of pthread_create
In the example at the bottom they are using:
pthread_create(&tinfo[tnum].thread_id, &attr, &thread_start, &tinfo[tnum]);
&thread_start
- with &
but in other examples I have seen online they were not using the &
:
pthread_create(&tinfo[tnum].thread_id, &attr, thread_start, &tinfo[tnum]);
I have also tested and it works without &
.
But which is the correct way?
Short answer: both are correct.
The signature of
pthread_create
is:So
start_routine
is a function pointer that takes avoid *
argument and returnsvoid *
.Back to your question, I assume
thread_start
is the name of the function, so&thread_start
is a function pointer which is correct.However,
thread_start
is correct, too, because the function name is automatically converted to a function pointer.