Replace shared mutex with waitgroup and atomic counter