adding volatile  finally fixed the bug