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

  • From: "Vyacheslav Egorov" <dmarc-noreply@xxxxxxxxxxxxx> (Redacted sender "vegorov" for DMARC)
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 24 Sep 2015 16:25:07 +0200

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: