Why are threads getting locked?