When your main program exits, all threads quit as well. This means that just one thread calling exit() (or if the main routine terminates) then other threads will quit.
You cannot just kill threads. If you kill threads which are doing work, then at best you get a memory leak, and at worst you get a deadlock. Either way it's not pretty.
Any resources which are cleaned up on process termination, will be cleaned up when the last thread exits (or if any thread calls exit() ). This includes memory (excluding shared memory, e.g. posix or sysv), file-like objects (if no other process has an open descriptor for them) and some other types of object.
Anything else which is persistent (e.g. temp files, some types of shared memory), you need to clean up yourself, either before you exit or (more robustly) at the beginning of the next run.