File tree 1 file changed +7
-0
lines changed
src/Microsoft.VisualStudio.Threading
1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,10 @@ public Task<T> GetValueAsync(CancellationToken cancellationToken)
224
224
// to synchronously block the Main thread waiting for the result
225
225
// without leading to deadlocks.
226
226
this . joinableTask = this . jobFactory . RunAsync ( valueFactory ) ;
227
+
228
+ // this ensures that this.joinableTask must be committed before this.value
229
+ Thread . MemoryBarrier ( ) ;
230
+
227
231
this . value = this . joinableTask . Task ;
228
232
}
229
233
else
@@ -245,6 +249,9 @@ public Task<T> GetValueAsync(CancellationToken cancellationToken)
245
249
resumableAwaiter ? . Resume ( ) ;
246
250
}
247
251
252
+ // this ensures that this.joinableTask cannot be retrieved before the conditional check using this.value
253
+ Thread . MemoryBarrier ( ) ;
254
+
248
255
return this . joinableTask ? . JoinAsync ( continueOnCapturedContext : false , cancellationToken ) ?? this . value . WithCancellation ( cancellationToken ) ;
249
256
}
250
257
You can’t perform that action at this time.
0 commit comments