I found out that two lines of code have the ambiguous meaning.
for (i = 0; i < NTHREADS; i++) {
#ifndef THREAD_POINTER
pthread_create(&thread_id[i], NULL, thread_function, NULL);
#endif
#ifdef THREAD_POINTER
pthread_create(&thread_id[i], NULL, &thread_function, NULL);
#endif
}
Here is the two lines of code. They behave the same action that creates NTHREADS numbers of thread. But the first function defines with the function name, and second function defines with the function name pointer. I thought it must be a function pointer so that the thread could be dynamically generated. These two must be two different function in POSIX library. I still don’t understand how this works. They are totally different from the syntax but with the same function name. As far as I know, the function name are only allowed to be the same in C++, but not in C.
If both function name(thread_function) and function name pointer(&thread_function) are void * type, the second one should be void **. So why the system behave the same.
P.S. This two lines of code were tested on MAC OS X 10.10.3 with clang compiler.