Mutex lock has some disadvantages: for example, what if you forget to unlock the mutex lock? In this case, any process that tries to lock the mutex lock that has been locked can wait for a long time. These threads become dead (zombie thread). This is a technical term, that is, a thread that exists but cannot do anything. Obviously, we don't want this to happen.
There is another problem with the mutex lock. Let's see what will happen in the following situations?
If the two threads depend on the same object (for example, the state of the game player, this state will be accessed for each frame. In a normal game, the Access frequency is about 30 ~ per second ~ 60 times ). At the same time, another thread needs to perform a lot of processing on this status (ifProgramThis function is not efficient, and the processing process takes up to 30 seconds. It is assumed that it can lock the mutex lock at any time, even if it does not use the locked object ). The first thread requires a lot of update information, but it actually stops for a long time, because it will wait until the second thread completes, so the game looks lagging.