File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed
src/Microsoft.VisualStudio.Threading Expand file tree Collapse file tree 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)
224224 // to synchronously block the Main thread waiting for the result
225225 // without leading to deadlocks.
226226 this . joinableTask = this . jobFactory . RunAsync ( valueFactory ) ;
227+
228+ // this ensures that this.joinableTask must be committed before this.value
229+ Thread . MemoryBarrier ( ) ;
230+
227231 this . value = this . joinableTask . Task ;
228232 }
229233 else
@@ -245,6 +249,9 @@ public Task<T> GetValueAsync(CancellationToken cancellationToken)
245249 resumableAwaiter ? . Resume ( ) ;
246250 }
247251
252+ // this ensures that this.joinableTask cannot be retrieved before the conditional check using this.value
253+ Thread . MemoryBarrier ( ) ;
254+
248255 return this . joinableTask ? . JoinAsync ( continueOnCapturedContext : false , cancellationToken ) ?? this . value . WithCancellation ( cancellationToken ) ;
249256 }
250257
You can’t perform that action at this time.
0 commit comments