Summary: critical_.d and critical.c use double check locking
                    the wrong way
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: druntime

--- Comment #0 from deadalnix <> 2011-09-05 18:12:19 PDT ---
First of all, I'm quite new here and hope I'm not plein wrong. If this is
please forgive me.

I was studying the druntime to know more about what's going on behing the hood
of D2, and I found out that synchronized may have been implemented the wrong

Consider this piece of code from critical_.d :

        if (!
            if (! // if, in the meantime, another thread didn't set it
       = dcs_list;
                dcs_list = dcs;
                pthread_mutex_init(&dcs.cs, &_criticals_attr);

The double check locking patern is used the wrong way here. may have
been set before the whole dcs struct has been initialized, thus leading to
undefined behaviour. Reordering instruction within the second if isn't
suffiscient as long as compiler, or CPU may reorder instruction and memory

The same goes for window code, which is very similar, and c code within
critical.c . I'm not sure which one is used and when). This code duplication
should eventually be reduced/suppressed in the process to avoid having a
problem poping in several place like we can see now.

I would be happy to help to resolve that problem, so don't hesitate to contact
me. Please be indulgent if the problem is irrevevelant because I didn't
understood the way druntime worked. I'm currently learn, and, even if I have a
strong background in devellopement even at low level, druntime is really new to
me and I'm still at the stage where I'm learning it.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to