Avoid having to wait for sets of N_THREAD tasks to finish simultaneously, thanks to a suggestion by @jojungge.