bug when loop creating threads