302
правки
Изменения
→Алгоритмы взаимного исключения
level[id] = j
victim[j] = id
'''while ''' '''exist ''' k: k != id '''and'''
level[k] >= j '''and'''
victim[j] == id:
===Алгоритм Лампорта (вариант <tex>1</tex>)===
'''threadlocal int''' id <font color=green>// 0 to N-1</font>
'''shared boolean''' want[N] '''init''' false
'''shared int''' label[N] '''init''' 0
'''def''' lock:
want[id] = true
label[id] = '''max'''(label) + 1 '''while ''' '''exists ''' k: k != id '''and'''
want[k] '''and'''
(label[k], k) < (label[id], id) :
===Алгоритм Лампорта (вариант <tex>2</tex>)===
'''threadlocal int''' id <font color=green>// 0 to N-1</font>
'''shared boolean''' want[N] '''init''' false
'''shared int''' label[N] '''init''' 0
'''def''' lock:
choosing[id] = true
label[id] = '''max'''(label!='''inf''') + 1
choosing[id] = false
'''while''' '''exists''' k: k != id '''and'''
(choosing[k] '''or'''
(label[k], k) < (label[id], id)) :
'''pass'''
'''def''' unlock:
label[id] = '''inf'''
==См. также==