try global flag

use atomic integer as global flag, not good.