Wait for stdout/stderr threads to end