|
发表于 2009-5-31 16:31:48
|
显示全部楼层
问题
1)thread 句柄为全局,递归过程中会相互覆盖
2)递归过程中起的多个thread 存在竞争冒险,从某一thread递归进入其他thread时,需yield当前,并在递归thread结束后重新resume (以callback识别)
修改前
function exec_alias(s)
temp_thread_path=coroutine.create(function (s)
local p_temp = Split(s,";");
for i,v in ipairs(p_temp) do
if nil~=string.find(v,"#%d+ ") then
world.Send(do_table[string.sub(v,string.find(v,"#%d+ "))]..string.sub(v,string.find(v," .+")));
elseif nil~=string.find(v,"#wa") then --´¦ÀíµÈ´ý
world.DoAfterSpecial(string.sub(v,string.find(v,"%d+")) / 2000,"coroutine.resume(temp_thread_path);",12);
coroutine.yield();
else
world.Send(v);
end
end
end)
coroutine.resume(temp_thread_path,s);
end
修改后
temp_thread_path = {}
function exec_alias(s, callback)
temp_thread_path=coroutine.create(function (s)
local p_temp = Split(s,";");
for i,v in ipairs(p_temp) do
if alias_table[v] then
exec_alias (alias_table[v], s)
coroutine.yield ()
elseif nil~=string.find(v,"#%d+ ") then
world.Send(do_table[string.sub(v,string.find(v,"#%d+ "))]..string.sub(v,string.find(v," .+")));
elseif nil~=string.find(v,"#wa") then
world.DoAfterSpecial(string.sub(v,string.find(v,"%d+")) / 2000,"resume_coroutine(\""..s.."\")",12);
coroutine.yield();
else
world.Send(v);
end
end
if callback then
resume_coroutine (callback)
end
end)
coroutine.resume(temp_thread_path,s);
end
function resume_coroutine (thread_name)
Note ("resume_coroutine : ", thread_name)
coroutine.resume(temp_thread_path[thread_name]);
end
[ 本帖最后由 duno 于 2009-5-31 04:36 PM 编辑 ] |
|