lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


John W <jwdevel@gmail.com> 于2022年3月11日周五 03:04写道:
>
> On 3/10/22, Oliver <oschmidt-mailinglists@gmx.de> wrote:
> >
> > You may have a look at mtint ( https://github.com/osch/lua-mtint#mtint ),
> > especially at Example 3 ( https://github.com/osch/lua-mtint#example-3 ).
> >
> > With mtint it is possible to interrupt a concurrently running Lua thread
> > from another thread ...
>
> As far as I can tell, fundamentally mtinit uses the "debug.sethook()"
> approach to achieve this interruption — is that correct? It's not
> doing some kind of platform-specific "raise an exception on thread X"
> functionality or somesuch, right?
>

You can override the official  coroutine.resume() and
coroutine.yield() to save the running coroutine into C side.
And when you want to interrupt a Lua VM from other OS thread, call
lua_sethook() with the running thread, and raise an error.

See https://github.com/cloudwu/skynet/blob/master/service-src/service_snlua.c#L520-L536


-- 
http://blog.codingnow.com