mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 11:03:12 +00:00
29 lines
551 B
Lua
29 lines
551 B
Lua
local skynet = require "skynet"
|
|
|
|
local trace_cache = {}
|
|
|
|
skynet.trace_callback(function(handle, ti)
|
|
-- skynet will call this function when the thread which create handle(traceid) end, and pass the time (ti)
|
|
print("TRACE",trace_cache[handle],ti)
|
|
trace_cache[handle] = nil
|
|
end)
|
|
|
|
local function f (i)
|
|
-- create a trace object
|
|
local traceid = skynet.trace()
|
|
-- name traceid in trace_cache[]
|
|
trace_cache[traceid] = "thread " .. i
|
|
|
|
for i=1,i do
|
|
skynet.sleep(i)
|
|
end
|
|
end
|
|
|
|
skynet.start(function()
|
|
for i = 1 , 100 do
|
|
skynet.fork(f, i)
|
|
end
|
|
end)
|
|
|
|
|