是否存在锁的算法Python版


#!/bin/python
## Available 当前可获取资源
## Mp 进程需要的最大资源
## Cp 当前进程占有的资源
## p1 [ Mp, Cp] 进程状态
Available = 20
p1 = [9, 4]
p2 = [50, 3]
p3 = [2, 1]
p4 = [6, 2]
P = [p1, p2, p3, p4]
while( P ):
    for p in P:
        Found = False
        if (p[0] - p[1]) < Available:
            Available = Available + p[1]
            P.remove(p)
            Found = True 
    if (not Found):
        print("Fail")
        break
print("Done")

    原文作者:牛平
    原文地址: http://blog.itpub.net/29757574/viewspace-2564173/
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞