Disk write in a "for" loop with RwMutex never happens
bauss
jacobbauss at gmail.com
Mon Aug 29 07:04:49 UTC 2022
On Sunday, 28 August 2022 at 22:46:17 UTC, Gavin Ray wrote:
> I've put the code, stripped to a minimal example here:
> - https://ldc.godbolt.org/z/fzsx3Tnnn
>
> You can see that the single write + read version of the code
> works just fine:
> ```
> pageData[0..4] = [1, 2, 3, 4]
> readData[0..4] = [1, 2, 3, 4]
> ```
>
> Where here, `pageData` is the data to be written to a file, and
> `readData` is the result of trying to read the freshly written
> file data.
>
> But if the same code is placed inside of a `for` loop, suddenly
> no writes occur:
> ```d
> pageData[0..4] = [0, 0, 0, 0]
> readData[0..4] = [0, 0, 0, 0]
>
> pageData[0..4] = [0, 0, 0, 1]
> readData[0..4] = [0, 0, 0, 0]
>
> pageData[0..4] = [0, 0, 0, 2]
> readData[0..4] = [0, 0, 0, 0]
>
> pageData[0..4] = [0, 0, 0, 3]
> readData[0..4] = [0, 0, 0, 0]
>
> pageData[0..4] = [0, 0, 0, 4]
> readData[0..4] = [0, 0, 0, 0]
>
> // ...
> ```
>
> Does anyone know what is happening here? It's really puzzling.
You probably need to flush the output.
More information about the Digitalmars-d-learn
mailing list