Bug 1091 – Wrong size reserved for critical sections

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2007-04-02T18:49:43Z
Last change time
2020-05-19T05:43:05Z
Keywords
wrong-code
Assigned to
Walter Bright
Creator
Frits van Bommel

Comments

Comment #0 by fvbommel — 2007-04-02T18:49:43Z
It looks like DMD on Linux only reserves 4 bytes for a critical section used to implement a synchronized {} block, while it should be at least 28 bytes. (A pointer to this is passed to _d_criticalenter, which takes a pointer to the following (C) struct: --- // from phobos/internal/critical.c typedef struct D_CRITICAL_SECTION { struct D_CRITICAL_SECTION *next; pthread_mutex_t cs; } D_CRITICAL_SECTION; --- According to my (32-bit) GCC the entire structure totals 28 bytes) This manifests itself in the following (synthetic) code: --- import std.stdio; void main() { synchronized { synchronized { writefln("Hello world!"); } } } --- The critical sections in the .data section are 4 bytes apart, yet should be 28 bytes large. Overlapping is _bad_. This code hangs when ran on my computer, but it's probably subject to the whim of the pthreads implementation... (Note: this is obviously useless code, I constructed it after figuring out what the problem was) AFAICT above D code should have been roughly equivalent to the following C code (linked to Phobos): --- #include <stdio.h> #include <pthread.h> #include <string.h> // from phobos/internal/critical.c typedef struct D_CRITICAL_SECTION { struct D_CRITICAL_SECTION *next; pthread_mutex_t cs; } D_CRITICAL_SECTION; D_CRITICAL_SECTION c1, c2; int main() { // not sure if this is necessary, but the space DMD // reserves is also zeroed, so... memset(&c1, 0, sizeof(D_CRITICAL_SECTION)); memset(&c2, 0, sizeof(D_CRITICAL_SECTION)); _d_criticalenter(&c1); _d_criticalenter(&c2); printf("Hello world!\n"); _d_criticalexit(&c2); _d_criticalexit(&c1); return 0; } --- Which runs just fine. (I used keyword "wrong-code" because "wrong-data" wasn't on the list ;) )
Comment #1 by thomas-dloop — 2007-04-04T15:37:02Z
Comment #2 by bugzilla — 2007-04-20T13:18:08Z
Fixed DMD 1.013
Comment #3 by dlang-bot — 2020-05-19T05:43:05Z
dlang/dub pull request #1946 "Make the testsuite re-runnable on OSX" was merged into master: - d51ae6b8bccea6d91c0c18e16c5326d83de56b44 by Geod24: testsuite: Make test for issue1091 re-runnable After the initial run, one couldn't run this test again as the expected message 'building configuration' would not be printed anymore. https://github.com/dlang/dub/pull/1946