0

I tried to run a demo that creates multiple threads using PThreads. But the IDE says the start_routine does not have a return value:

void *PrintHello(void *threadid)
{
   long tid;
   tid = (long)threadid;
   printf("Hello World! It's me, thread #%ld!\n", tid);
   pthread_exit(NULL);
}

I wonder if there is really an error, or I should adjust the settings of IDE (I am using VS2013).

Thanks!

Craig
  • 591
  • 2
  • 5
  • 10
  • Your function does not return anything, but its type is `void*` – Sergey Kalinichenko Apr 18 '16 at 02:41
  • The language allows a non-void-returning function to not return a value, but the result is undefined behavior so you should always return a value anyway. See also: http://stackoverflow.com/questions/1610030/why-does-flowing-off-the-end-of-a-non-void-function-without-returning-a-value-no – Jeremy Friesner Apr 18 '16 at 02:45
  • 1
    Replacing `pthread_exit(NULL);` with `return NULL;` should make everything happy. You don't need to call `pthread_exit` in a thread's start routine since it's implicitly called when you return the value instead. – Joachim Isaksson Apr 18 '16 at 02:47
  • Thank you guys! As Joachim said, I called pthread_exit in the end and replaced the pthread_exit with return and it works. – Craig Apr 18 '16 at 02:52
  • @JeremyFriesner: In this case the function never returns, because `pthread_exit()` does not return to the caller. – caf Apr 18 '16 at 05:19
  • @caf I know that, and you know that, but the IDE (apparently) doesn't know that. – Jeremy Friesner Apr 18 '16 at 14:05

0 Answers0