ExtJS,它是线程安全的吗?
我用一个变量来限制用户的查询操作,就像操作系统的临界区一样。
//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
,并将新的 param
和 callback
传递给 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
示例中的代码不足以解决问题,并且问题可能根本与 Ext JS 无关。请提供完整的源代码。
这里可能是一个常见的 Javascript 错误,即双重输入函数和内部函数(如
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
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.