Shared�memory�model � Processes�communicate�by�applying�operations�on� and�receiving�responses�from� shared�objects Shared�memory:�Part�I � A�shared�object�is�a�state�machine � States � Operations/Responses � Sequential�specification � Examples:�read�write�registers,�T&S,C&S,LLSC,… FDC�� Summer�Term�2007 � � Max�Planck�Institute�for�Software� Systems � � � � � � � � � � � � � ������������������ � � ������������������ Registers Shared�memory�guarantees A�read�write�register�object: Processes�invoke�operations�on�the�shared� objects�and: � Stores� values�� (in�an�ordered�set�V) � Exports�two�operations:�read�and�write � Liveness:�the�operations�eventually�return� � Write�takes�an�argument�in�V�and�returns�ok something � Read�takes�no�args and�returns�a�value�in�V � Safety:�the�operations�never�return� anything�incorrect� � � � ������������������ � ������������������ Liveness Wait�freedom � An�operation�is� complete� in�a�run�R�if�its� The�liveness property�in�this�class:� invocation�is�followed�by�a�response�in�R � write(v)���>�ok In�every�run, every�operation�invoked�by�a� � read()��>�a�value�in�V correct�process�is�complete � A�process�invoking�an�operation�may�fail� before�receiving�a�response � The�liveness property�in�this�class:�in�every� run, every�operation�invoked�by�a�correct� process�is�complete � � � ������������������ � ������������������ 1
A�shared�memory�run Safety�(registers) Informally,�every�read�operation�returns�the� ���������� �� ���������� �� “last” written�value�(the�argument�of�the� p1 “last” write�operation) �������� � � What�is�“last” if�operations�may�overlap p2 �������� � ���������� p3 � � � ������������������ � ������������������ A�shared�memory�run Operation�precedence � Operation�op1�is�said�to� precede� operation� ���������� �� ���������� �� op2�in�a�run�R�if�the�response�of�op1� p1 precedes�(in�global�time)�the�invocation�of� �������� � op2�in�R � If�neither�op1�precedes�op2�nor�op2� p2 precedes�op1�than�op1�and�op2�are� �������� � �������� � concurrent p3 � �� � ������������������ � ������������������ Operation�precedence Safety�criteria � Safe�registers:�every�read�that�does�not�overlap� ��� ��� a�write�returns�the�last�written�value� � Regular�registers:�every�read�returns�the�last� p1 written�value,�or�the�concurrently�written�value� ��� (assuming�one�writer) p2 ��� ��� � Atomic�registers:�regular�+�the�operations�can�be� totally�ordered,�preserving�the�precedence� relation�(strict�linearizability) p3 � ≈ if�read1�returns�v,�read2�returns�v’,�and�read1� precedes�read2,�then�write(v’)�cannot�precede�write(v)� �� �� � ������������������ � ������������������ 2
Safe�register Regular�register ���������� �� ���������� �� ���������� �� ���������� �� p1 p1 �������� � �������� � p2 p2 �������� �������� �������� �������� p3 p3 �� �� � ������������������ � ������������������ Atomic�register Space�of�registers � Values:�from�binary�(V={0,1})�to�multi�valued ����������� ����������� � Number�of�readers�and�writers:�from�1�writer�1� p1 reader�(1W1R)�to�multi�writer�multi�reader� (NWNR)� �������� � Safety�criteria:�from�safe�to�atomic p2 �������� �������� 1W1R�binary�safe�registers�can�be�transformed� into�NWNR�multi�valued�atomic�registers! p3 �� �� � ������������������ � ������������������ Outline�of�the�class 1W1R�(binary�safe)��>�1WNR�(binary�safe) Let�p1�be�the�only�writer�and�0�be�the�initial�value 1W1R�binary�safe��>�1WNR�binary�safe 1. Code�for�process�pi: 1WNR�binary�safe��>�1WNR�binary�regular initially: 2. array�R[1..N]�of�1W1R�registers�:=�0 N 1WNR�binary�regular��>�1WNR�multi� 3. //�For�all�i,�R[i]�is�written�by�p1�and�read�by�pi� valued�regular upon�read() Atomic�NWNR�registers:�definitions 4. return�R [ i ] .read() upon�write(v)��//�if�i=1� for�all�j�do�R [ j ] .write(v) return�ok �� �� � ������������������ � ������������������ 3
1W1R�(binary�safe)��>�1WNR�(binary�safe) 1WNR�binary�safe��>�1WNR�binary�regular Let�p1�be�the�only�writer�and�0�be�the�initial�value � Correctness:� Code�for�process�p1: � enough�to�consider�a�read�that�does�not�overlap� initially: with�any�write lv :=�0�\\ last�written�value � the�last�written�value�cannot�be�missed upon�write(v)� � Works�also�for�multi�valued�and�regular� if�v�≠ lv then registers lv :=�v for�all�j�do�R [ j ] .write(v) return�ok �� �� � ������������������ � ������������������ Binary��>�M�valued�(1WNR�regular)� 1WNR�binary�safe��>�1WNR�binary�regular Code�for�process�pi: � Correctness:� initially: � R[]�is�touched�only�to�change�the�written�value array�R[0,..M�1]�of�1WNR�registers�:=�[1,0,…,0] � =>�both�0�and�1�are�legitimate�values�in�case�of� concurrency upon�read() for�j�=�0�to�M�1�do �������� �������� �������� if�R[j].read()�=�1 then return(j) p1 upon�write(v)��//�if�i=1� �������� �������� � R [ v ] .write(1) for�j=v�1�down�to�0�do�R [ j ] .write(0) p2 �������� �������� � return�ok p3 �� �� � ������������������ � ������������������ Histories Binary��>�M�valued�(1WNR�regular) � Correctness:� � only�the�last�or�concurrently�written�value�can� A�history�is�a�sequence�of�invocation�and� be�returned responses E.g.,�p1�>write(0),�p2�>read(),p1�>ok,p2�>0,… � HW:�what�if: A�history�is�sequential�if�every�invocation�is� � for�j=0�to�v�1�do�R [ j ] .write(0) followed�by�a�corresponding�response � upon�write(v)��//�if�i=1� E.g.,�p1�>write(0),�p1�>ok,�p2�>read(),p2�>0,… for�j=v�1�down�to�0�do�R [ j ] .write(0) R [ v ] .write(1) (A�sequential�history�has�no�concurrent�operations) return�ok �� �� � ������������������ � ������������������ 4
Recommend
More recommend