我目前正在努力掌握线程。我有一种感觉,这可能与我的范围有关;但是,我看不出我哪里出了问题。
我的 CFC 包含以下功能:
<cfcomponent output="false" hint="thread stuff.">
<cffunction name="threadTest" access="public" returntype="struct">
<cfscript>
local.lstOne = "1,2,3,4,5,6";
local.a = [];
local.s = {};
local.lst = "";
for(local.x = 1; local.x lte listlen(local.lstOne,','); local.x++){
local.lst &= (len(local.lst) gt 0) ? ',thr#local.x#' : 'thr#local.x#';
thread action="run" name="thr#local.x#" nIndex="#local.x#" aArray="#local.a#"{
thread.y = attributes.nIndex;
thread.aArray = attributes.aArray;
if(thread.y mod 2){
thread.c = 1;
} else {
thread.c = 0;
}
thread.stArgs = {};
thread.stArgs.nMod = thread.c;
arrayAppend(thread.aArray, thread.stArgs);
}
}
threadJoin(local.lst);
local.s.counts = local.a;
return local.s;
</cfscript>
</cffunction>
</cfcomponent>
我有一个 CFM 页面,看起来有点像这样:
<cfscript>
theThread = createObject( "component", "ThreadStuff" ).init();
theThread.threadTest();
</cfscript>
当我运行它时,coldfusion 会返回错误Element X is undefined in LOCAL。.
我无法弄清楚为什么在循环的第一次迭代后它会丢失local.x(我已经通过在循环开始和循环结束时进行转储来证明这一点,并且它无法到达本地.x = 2)。
我可能哪里出错了?