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
[...]

But if the same code is placed inside of a `for` loop, suddenly no writes occur:
[...]

Does anyone know what is happening here? It's really puzzling.

Relevant pieces of the code:

```d
class DiskManager
{
    void writePage(PageId pageId, ubyte[PAGE_SIZE] pageData)
    {
        synchronized (dbIOMutex.writer)
        {
            dbFile.seek(pageId * PAGE_SIZE);
            dbFile.rawWrite(pageData);
        }
    }
}

void singleReadWrite()
{
    PageId pageId = 0;

    diskManager.writePage(pageId, pageData);
}

void multiReadWrite()
{
    PageId pageId = 0;

    foreach (i; 0 .. 10)
    {
        diskManager.writePage(pageId, pageData);
    }
}
```

You never change `pageId`. So as far as I can tell, you're always `seek`-ing to the same position, and you just overwrite the same piece of the file again and again.

Reply via email to