2

私は現在、スレッドを理解するのに苦労しています。私のスコープと関係があるのではないかと感じています。ただし、これのどこが間違っているのかわかりません。

私の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)。

どこが間違っているのでしょうか?

4

2 に答える 2

0

問題が変数local.xがインクリメントされていないことである場合は、すべてのスレッドのものをコメントアウトすることから始めます。ローカルのwritedumpに置き換えます。ループの前後にもローカルスコープをライトダンプします。

local.xの増分を取得したら、空のスレッドを追加します。ローカルスコープのwritedumpを続行して、これが問題の原因であるかどうかを確認します。local.xがまだインクリメントしている場合は、問題の原因となるビットが見つかるまで、非常に小さなコードを追加します。

于 2013-02-19T23:51:08.463 に答える