loc: protect the cmd function by mutex to avoid crash