terminate threads and main program