import threadingimport timelock=threading._RLock()words=["a","b","d","b","p","m","e","f","b"]def increase(): global words for count in range(5): lock.acquire() print("A acquired") for i in range(len(words)): for j in range(i+1,len(words)): if words[j]
words[i]: t=words[i] words[i]=words[j] words[j]=t print("D ",words) time.sleep(1) lock.release()A=threading.Thread(target=increase)A.setDaemon(False)A.start()D=threading.Thread(target=decrease)D.setDaemon(False)D.start()print("The End")程序结果:A acquiredA ['a', 'b', 'b', 'b', 'd', 'e', 'f', 'm', 'p']The EndD acquiredD ['p', 'm', 'f', 'e', 'd', 'b', 'b', 'b', 'a']D acquiredD ['p', 'm', 'f', 'e', 'd', 'b', 'b', 'b', 'a']A acquiredA ['a', 'b', 'b', 'b', 'd', 'e', 'f', 'm', 'p']A acquiredA ['a', 'b', 'b', 'b', 'd', 'e', 'f', 'm', 'p']D acquiredD ['p', 'm', 'f', 'e', 'd', 'b', 'b', 'b', 'a']D acquiredD ['p', 'm', 'f', 'e', 'd', 'b', 'b', 'b', 'a']D acquiredD ['p', 'm', 'f', 'e', 'd', 'b', 'b', 'b', 'a']A acquiredA ['a', 'b', 'b', 'b', 'd', 'e', 'f', 'm', 'p']A acquiredA ['a', 'b', 'b', 'b', 'd', 'e', 'f', 'm', 'p']你认为结果可能吗?