Join threads before the thread is released

Threads cannot be joined before pthread_exit has been called.
Because of that, we place the pthread_join method in gomp_free_thread
instead of placing it in the proposed gomp_team_end method.
Method gomp_free_thread is called only by the master thread and all
worker threads, which will be joined, have already been released.

We also need to create the threads joinable. Thus, when no affinity
is required, we create the threads with the attribute PTHREAD_CREATE_JOINABLE
instead of the attribute PTHREAD_CREATE_DETACHED.
Remove unnecessary included headers