1 If a function can use local variables, try to use local variables. These variables allocated on the stack do not affect a function being called in different places.
2 If there is data shared by multiple functions, the most basic method is to lock the variables shared by multiple functions.
3 Consider using thread local storage
Here is a tutorial
Here are examples
He means to use shared_ptr wherever possible (ignore me
Borrow the answer from how to make an application thread safe?.
1 If a function can use local variables, try to use local variables. These variables allocated on the stack do not affect a function being called in different places.
2 If there is data shared by multiple functions, the most basic method is to lock the variables shared by multiple functions.
3 Consider using thread local storage