Atomic updates

monarch_dodra monarchdodra at gmail.com
Tue Jan 22 01:47:24 PST 2013


On Tuesday, 22 January 2013 at 09:26:25 UTC, cal wrote:
> On Tuesday, 22 January 2013 at 08:12:03 UTC, qznc wrote:
>> On Tuesday, 22 January 2013 at 00:10:22 UTC, bearophile wrote:
>>> I suggest to put your code on Rosettacode now, and then we'll 
>>> do the changes there... As you see in other answers, both me 
>>> and monarch_dodra have other ideas for improvements.
>>
>> Ok, posted it.
>>
>> http://rosettacode.org/wiki/Atomic_updates#D
>>
>> I incorporated some of your and monarch_dodra's suggestions.
>
> Just curious: in the transfer function, why do you lock/unlock 
> the lower bucket number first? Why does the order matter?

Avoids deadlock.

imagine 2 threads:
a: from 2 to 5.
b: from 5 to 2.

If both threads acquire their first lock, then you have a dead 
lock, and your program is basically dead.

By always locking low first, you avoid the deadlock in a rather 
simple but elegant way.


More information about the Digitalmars-d-learn mailing list