implement main thread loop
refactor mutex lock & unlock