Terminate threads before to exit main()