Thread fail to geneate right number for pre-calculated pulses

Hi Xuan,

Try int pulses = 0;