add mutex for main_thread vs socket_thread