Use mutex to avoid data race