Women in Technology

Hear us Roar



Article:
  Implementing Mutual Exclusion for AJAX
Subject:   Still a race-condition?
Date:   2007-02-16 07:13:01
From:   GICodeWarrior

Have a look at line three of the Command code:
3 this.id = ++Command.NextID;


This entire algorithm hinges on the fact that the 'threads' are uniquely numbered. The line above is where they are numbered. That line is probably not atomic. If that line is not atomic, two 'threads' could end up with the same number.


I don't think it is possible to prove that the above line is atomic because it depends on the interpreter (you could prove it for one interpreter but not all). Therefore, this example would appear to be broken, or am I just nuts?


~Rusty

Full Threads Newest First

Showing messages 1 through 1 of 1.

  • Still a race-condition?
    2007-08-30 11:18:28  polyglot [View]

    Because it is hard to find any promises from JavaScript implementors around these sorts of issues, it seems that no solution would be provable, so I went with something practical.
    For those worried that the increment operator is not atomic, one could replace it with a large random large number which would make the odds of failure small (e.g. one in 4 billion) and known.
    I guess it depends on which operation one has the least paranoia about. :-)