Q:

pthread_join success = thread entirely executed?

I have a question about pthreads whith this little C source:
int calc = 0;

void func(void* data){
    calc = 2 * 2;
    return NULL;
}  

int main(){
    pthread_t t;
    if(0==pthread_create(&t,NULL,func,NULL)){
       if(0==pthread_join(t,NULL)){
           printf("Result: %d\n",calc);  // 4 ?
       }
    }
}

If pthread_join return success, is "func" always executed entirely ? (calc always equal 4 on printf ?).

A:

The function pthread_join returns zero when the function success.
The documentation says that pthread_join blocks until the thread ends, so, with some applied logic one can easily conclude that the thread has ended.
In the other side, pthread_join fails in different ways:

When the handle is invalid: EINVAL
When a deadlock has been detected: EDEADLK
There is another possible error, recomended by the open group, but depending on the implementation: ESRCH, when it detects that the thread handle is being used past the end of the thread.

If you want to know more you should take a look at the documentation

