The space for the stacks of all threads in a process is carved out of the memory previously allocated for the stack of the process as a whole (shown in fig). Thus, the termination of the main program terminates the thread as well.
To illustrate: Write a program creating the threads in the detached state. Run the program with the gdb and you observe that the thread exits just when the program terminates.
Starting program: /home/avairavan/CProg/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Main Program Starting.
[New Thread 0x7ffff77f5700 (LWP 3484)]
Main Program Exiting.
[Thread 0x7ffff77f5700 (LWP 3484) exited]