0

i use a variable to limit the query operation of users,just like the critical area of OS。

//call 'fun' only if it is free(at the end of fun ,it will do isQuery=true)
var getInfo= function(param,callback){
    if(!isQuery){   
     isQuery = true;
     fun(param,callback);
    }
}

but when two query requests happened at the same time, the param went wrong ,like A recieved param of B while B didn't call fun successfully! I think it is a multithreading problem,

When A was authorized (isQuery == false) to call 'fun',and just before the sentence 'fun(param,callback)' was going to execute, B called getInfo ,and passed new param and callback to getInfo,but now,isQuery == true, B is not authorized,then getInfo tured to execute fun(param,callback) with B's arguments,so it went wrong,i'm right?

ps: please forgive my poor english...

ps2:thank you very much,but i still feel unsure, maybe it is not a multithreading problem,but how does that happen?there is only one instance of 'getInfo',so will it always keep the latest argument?

hmakholm left over Monica
  • 23,074
  • 3
  • 51
  • 73
ygg
  • 73
  • 1
  • 8
  • 1
    JS runs in one thread in all browsers but chrome http://www.sitepoint.com/multi-threading-javascript/ – Oskar Kjellin Aug 20 '11 at 12:05
  • I guess it is more about 'request-safety' than thread safety – Mchl Aug 20 '11 at 12:09
  • 1
    [Here](http://stackoverflow.com/questions/124764/are-mutexes-needed-in-javascript/124832#124832) I believe is the answer to your question. – Victor Aug 20 '11 at 12:35

1 Answers1

0

The code in the example is not enough to solve the problem and the problem is probably not related to Ext JS at all. Please provide the full source code.

What you have here is probably a common Javascript mistake with a double entering function with an inner function like this

    function broken(url, x) {

        var params = { something : x }

        function post() {
            $("#elem).get(url, params);
        }   

        post();

    }

broken() keeps only one params state inside it and delegates this to closures. Because you enter the function twice, when the initial params state is still being used, the first params state gets overridden.

To work around the problem o nly pass function parameters forward as is, do not create var locals in functions which may be double-entered.

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435