Changed the spin function not rely on clock()
Changed clFlush to clFinish