add thread synchronization

Signed-off-by: jonnyhsy <jonnyhsy@foxmail.com>