dotnet / dotnet/dotnet-api-docs
`SpinWait` example ignores compiler HW/optimization
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
If I am not wrong example:
- [page](https://learn.microsoft.com/en-us/dotnet/api/system.threading.spinwait?view=net-7.0#examples)
- [src](https://github.com/dotnet/dotnet-api-docs/blob/13d97c7e536ce822c000883dba873a79d5d6e841/snippets/csharp/System.Threading/SpinWait/Overview/spinwait.cs)
shows incorrect usage. Examples should be complete, understandable and most importantly correct.
Since `someBoolean` is accessed by multiple threads, it must be provided with synchronization manner for `r/w` ops. Similar [example](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/volatile#example) can be seen in _volatile (C# Reference)_ page. This one explicitly points out need for synchronization between threads.
Contributor guide
Assessment
This issue has not been assessed yet.