Struct with default ctor (Was: [dmd-beta] dmd 2.064 beta take 2)

Walter Bright newshound2 at digitalmars.com
Sun May 19 16:29:51 PDT 2013


On 5/19/2013 4:06 PM, deadalnix wrote:
> On Sunday, 19 May 2013 at 22:32:58 UTC, Andrei Alexandrescu wrote:
>> How was there a bug if everything was properly synchronized? You either
>> describe the matter with sufficient detail, or acknowledge the destruction of
>> your anecdote. This is going nowhere.
>>
>
> I explained over and over. A field is initialized to null, while the object lock
> is owned, and later to its value, while it is locked. In the meantime, another
> thread access the object, owning the lock, assuming the field is always
> initialized.

so, you have:
==========================
Thread A     Thread B

lock
    p = null
unlock
              lock
                 *p = ...
              unlock
lock
    p = new ...
unlock
==========================
Although you are using locks, it still isn't properly synchronized. Changing the 
p=null to p=someothernonnullvalue will not fix it.


More information about the Digitalmars-d mailing list