-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Closed
Milestone
Description
Hi. On the following example
public ValueTask<int> CachedFunc()
{
return (cache) ? new ValueTask<int>(cacheResult) : new ValueTask<int>(LoadCache());
}
private bool cache = false;
private int cacheResult;
private async Task<int> LoadCache()
{
// simulate async work:
await Task.Delay(100);
cacheResult = 100;
cache = true;
return cacheResult;
}
Shouldn't cache and cacheResult variable be accesses through some kind of barrier like Volatile or interlocked?
They are being written and read from different threads... right?
Regards.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: dc229b53-a548-4ef8-86b9-58670a81344a
- Version Independent ID: aeb15230-e1cc-df50-7edb-fb50164e13be
- Content: What's New in C# 7.0 - C# Guide
- Content Source: docs/csharp/whats-new/csharp-7.md
- Product: dotnet-csharp
- GitHub Login: @BillWagner
- Microsoft Alias: wiwagn