[Issue 13727] std.stdio.File not thread-safe

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Nov 13 17:17:14 PST 2014


https://issues.dlang.org/show_bug.cgi?id=13727

--- Comment #5 from Vladimir Panteleev <thecybershadow at gmail.com> ---
(In reply to Steven Schveighoffer from comment #4)
> Oh god! More locks :)

Assuming we don't need to lock for the actual I/O operations (read/write), I
think the impact for locking on some O(1)-ish operations shouldn't be too bad
compared to the cost of the actual I/O.

> I strongly believe we should fix the issue in DMC. Can we create a C++
> program that will exhibit the same issue?

Yes:

///////////////////////////// test.c ////////////////////////////
#include <windows.h>
#include <stdio.h>

DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
    for (int i=0; i<100; i++)
    {
        int res;
        FILE* f = fopen("test.c", "rb");
        if (!f) { printf("fopen failed\n"); return 1; }
        res = fclose(f);
        if (res) { printf("fclose failed\n"); return 1; }
    }
    return 0;
}

void main()
{
    for (int i=0; i<10; i++)
    {
        DWORD dwThreadId;
        CreateThread(NULL, 0, &ThreadProc, NULL, 0, &dwThreadId);
    }
}
/////////////////////////////////////////////////////////////////

--


More information about the Digitalmars-d-bugs mailing list