Little misbeahvior in code example for SpinWait
- Dominant language
- No language data
- Stars
- 4.8k
- Forks
- 6.1k
- Avg merge
- 15h 21m
- Merged PRs (30d)
- 370
Description
---
**Issue moved from MicrosoftDocs/feedback#3946**
- Please respond to @pomatuchto.
---
_From @pomatuchto on Friday, August 11, 2023 4:43:01 AM_
Code example for SpinWait: https://learn.microsoft.com/en-us/dotnet/standard/threading/how-to-use-spinwait-to-implement-a-two-phase-wait-operation#example
In the method Latch.Wait(int timeout) Stopwatch uses to measure amount of time elapsed during the first phase of wait operation. Then in the second phase timeout passed to this method decreases by this measured timelapse.
The problem: stopwatch is reinitialized every iteration of outer while cycle. Thus by the start of second phase we didn't actually measured elapsed time at all.
---
#### Document Details
⚠ *Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.*
* ID: 09ab0f1a-b6ee-8222-2d88-a3ace8bd05b7
* Version Independent ID: b3ceb6f8-2b2d-68ec-a76b-5c6e1b16be92
* Content: [How to: Use SpinWait to Implement a Two-Phase Wait Operation](https://learn.microsoft.com/en-us/dotnet/standard/threading/how-to-use-spinwait-to-implement-a-two-phase-wait-operation#example)
* Content Source: [docs/standard/threading/how-to-use-spinwait-to-implement-a-two-phase-wait-operation.md](https://github.com/dotnet/docs/blob/main/docs/standard/threading/how-to-use-spinwait-to-implement-a-two-phase-wait-operation.md)
* Product: **dotnet-fundamentals**
* GitHub Login: @BillWagner
* Microsoft Alias: **wiwagn**
Contributor guide
Assessment
This issue has not been assessed yet.