On Tuesday, 22 January 2013 at 09:47:25 UTC, monarch_dodra wrote:
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.

Ah neat. And what about the case from = to? Why doesn' that deadlock in this code? (Concurrency is rather new to me)

Reply via email to