fixed return value in pthread loop