File tree Expand file tree Collapse file tree 2 files changed +35
-4
lines changed Expand file tree Collapse file tree 2 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -163,8 +163,13 @@ def initialize
163
163
164
164
def read ( tvar )
165
165
Concurrent ::abort_transaction unless valid?
166
- @read_log . push ( ReadLogEntry . new ( tvar , tvar . unsafe_version ) )
167
- tvar . unsafe_value
166
+
167
+ if @write_log . has_key? tvar
168
+ @write_log [ tvar ]
169
+ else
170
+ @read_log . push ( ReadLogEntry . new ( tvar , tvar . unsafe_version ) )
171
+ tvar . unsafe_value
172
+ end
168
173
end
169
174
170
175
def write ( tvar , value )
Original file line number Diff line number Diff line change @@ -120,11 +120,11 @@ module Concurrent
120
120
end
121
121
end
122
122
123
- a . wait
124
123
Concurrent ::atomically do
124
+ a . wait
125
125
expect ( t . value ) . to eq 0
126
+ b . count_down
126
127
end
127
- b . count_down
128
128
end
129
129
130
130
it 'provides strong isolation' do
@@ -147,11 +147,37 @@ module Concurrent
147
147
end
148
148
149
149
it 'nests' do
150
+ t = TVar . new ( 0 )
151
+
150
152
Concurrent ::atomically do
153
+ expect ( t . value ) . to eq 0
154
+ t . value = 1
151
155
Concurrent ::atomically do
156
+ expect ( t . value ) . to eq 1
157
+ t . value = 2
152
158
Concurrent ::atomically do
159
+ expect ( t . value ) . to eq 2
160
+ t . value = 3
153
161
end
162
+ expect ( t . value ) . to eq 3
163
+ t . value = 4
154
164
end
165
+ expect ( t . value ) . to eq 4
166
+ t . value = 5
167
+ end
168
+
169
+ expect ( t . value ) . to eq 5
170
+ end
171
+
172
+ it 'reflects transactional writes from within the same transaction' do
173
+ t = TVar . new ( 0 )
174
+
175
+ Concurrent ::atomically do
176
+ expect ( t . value ) . to eq 0
177
+ t . value = 14
178
+ expect ( t . value ) . to eq 14
179
+ t . value = 2
180
+ expect ( t . value ) . to eq 2
155
181
end
156
182
end
157
183
You can’t perform that action at this time.
0 commit comments