[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Is is possible to use just one lua virtual machine in C coroutine framework?
- From: "=?gb18030?b?0KHFwLPm?=" <caterchong@...>
- Date: Wed, 25 Jul 2018 10:03:22 +0800
I've worked on a C coroutine framework implemented with ucontext.
For each client request, the framework will alloc a C coroutine to process the request.
I wanna add lua to this system. However, I met some problems.
It's hard to change C coroutine to lua coroutine, since it's a big codebase. Use lua as glue to aggregate all the C api seems a reasonable way.
So lua will not use coroutine, leave the coroutine to C.
However, the C stack changes when switch C coroutines. It's possible to use multiple lua virtual machine, one for each C coroutine. But it is not efficient. Each creation of C Coroutine will need create a new virtual machine and load all the scripts.
If I use only one Lua virtual machine,and create thread for each coroutine, it's much more light-weighted and scripts can be shared among different lua_thread. However, the switch execution of C coroutine requires lua_thread to be suspended and resumed. Since lua only allow one running lua_thread.
Are these any solutions for this problem? Thanks in advance.