The lock python

 Avoid multiple threads to defend the same piece of data when an error occurs, it is locked to prevent this problem

Personal understanding: When printing the result is alternately print, but if demand is required after printing the contents of a thread, go to print another thread, we need to use a lock

Unlock print result: increase the sleep time, it will alternate every second print out a, b values

 

 Then suppose there is a demand, it is necessary to let the thread after the run is completed 1, 2 thread was running, or turn 2 and then 1 at the beginning of the program, create a lock

 

Print after the lock is: because of the increase of sleep time, so probably every 1 second will print out a result

 

Guess you like

Origin www.cnblogs.com/mihoutao/p/10973260.html