Skip to content

Observation on "Generalized async return types" #7506

@clperez

Description

@clperez

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions