Replies: 3 comments 14 replies
-
|
同一个service,任何一个时刻都只会在其中一个物理线程上运行。这可能就是你认为的并行,如果你需要让多个物理线程同时工作,你需要多个service。 但是一个service可以有多个continue, call只是阻塞了当前的continue,并不会阻塞service(service和vm是等价的)。 |
Beta Was this translation helpful? Give feedback.
2 replies
-
|
我尝试出了一个最小复现模型: service1 的代码 local serviceId = ltask.spawn("service2", ltask.self())
ltask.send(serviceId , "func1")
ltask.send(serviceId , "func2")
ltask.send(serviceId , "print")service2 的代码 local S = {}
local a = ""
function S.func1()
a = a .. "1"
require 'meta' -- 这里很关键,一定是require一个之前没被加载的文件
a = a .. "2"
end
function S.func2()
a = a .. "3"
end
function S.print()
print("a is", a)
end我这里最终输出是: a is 13 |
Beta Was this translation helpful? Give feedback.
10 replies
-
这里我想再请教下:
local function update()
while not quit do
-- update
ltask.sleep(20)
end
ltask.wakeup(quit)
end
ltask.fork(update) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
我在一个函数里面写了下面三行代码
其中func1的逻辑比较重(还涉及到IO操作),func2的逻辑比较少
我发现 func1 和 func2好像是并行执行的,如果分别在里面加入print语句,func2里面的输出还会出现在func1前面。
这是正常的吗 = =
这种情况下,我也不太想用call,因为call会阻塞当前vm,直到返回
Beta Was this translation helpful? Give feedback.
All reactions