私は現在、スレッドを理解するのに苦労しています。私のスコープと関係があるのではないかと感じています。ただし、これのどこが間違っているのかわかりません。
私の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が失われる理由がわかりません(ループの開始時とループの終了時にダンプを実行することでこれを証明しましたが、到達できません)。 local.x = 2)。
どこが間違っているのでしょうか?