Re: Is it OK to swapcontext() in C function called by lua?

  • From: Ran Xie <hi.nareix@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Sun, 27 Sep 2015 17:27:18 +0800

Thanks a lot :)

2015-09-24 22:25 GMT+08:00 Vyacheslav Egorov <dmarc-noreply@xxxxxxxxxxxxx>:

This should be fine. Trace is stopped/aborted before you enter foo
anyway. So the tracing machinery should be reset.

You should be wary of swapcontext'ing from inside an FFI call though -
usual re-entering Lua constraint applies[1]

[1] http://luajit.org/ext_ffi_semantics.html#callback

// Vyacheslav Egorov


On Tue, Sep 22, 2015 at 6:53 PM, Ran Xie <hi.nareix@xxxxxxxxx> wrote:

int foo(lua_State *L) {
...
swapcontext();
...
}

void thread(L) {
lua_dostring(L, "foo()");
}

int main() {
L1 = lua_newthread(L);
L2 = lua_newthread(L);
L3 = lua_newthread(L);
makecontext(thread, L1); swapcontext();
makecontext(thread, L2); swapcontext();
makecontext(thread, L3); swapcontext();
return 0;
}

Will this work without BUG?
I wonder if the trace jit subsystem not support to do so.



Other related posts: