ExtJS,它是线程安全的吗?

发布于 2024-11-30 19:55:28 字数 790 浏览 0 评论 0原文

我用一个变量来限制用户的查询操作,就像操作系统的临界区一样。

//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);
    }
}

但是当两个查询请求同时发生时,param出错了,就像A收到了param B 的 而 B 没有成功调用 fun!我认为这是一个多线程问题,

当 A 被授权 (isQuery == false) 调用 'fun' 时,并且就在句子 'fun(param,callback) 之前' 本来要执行,B 调用了 getInfo ,并将新的 paramcallback 传递给 getInfo,但是现在, isQuery == true,B没有被授权,然后getInfo尝试用B的参数执行fun(param,callback),所以出错了,对吗?

ps:请原谅我糟糕的英语...

ps2:非常感谢你,但我仍然不确定,也许这不是一个多线程问题,但这是怎么发生的?只有一个“getInfo”实例,所以会吗总是保留最新的论点?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难得心□动 2024-12-07 19:55:28

示例中的代码不足以解决问题,并且问题可能根本与 Ext JS 无关。请提供完整的源代码。

这里可能是一个常见的 Javascript 错误,即双重输入函数和内部函数(如

    function broken(url, x) {

        var params = { something : x }

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

        post();

    }

broken())只在其中保留一个参数状态,并将其委托给闭包。因为您输入该函数两次,所以当仍在使用初始参数状态时,第一个参数状态将被覆盖。

要解决此问题,只需按原样向前传递函数参数,不要在可能重复输入的函数中创建 var 局部变量。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文