Comments (6)
Well, as a matter of fact, as you point out, there is no way for you to obtain the handle of a lane if you did not store it yourself. In fact it relates to an old design decision of Lanes, to make lanes non-transferable, and therefore non-manipulable, from more than one thread. I'm not sure it would be easy to change that while ensuring that no crash will occur if somebody wants to abuse the mechanism.
However, I think that you could achieve the intended result by sending a message through a linda, and have all your lanes terminate gracefully when they catch it.
from lanes.
😁 Well, our issue is a bit more complex. I will try to describe.
We have Lua running in an embedded device and using ZeroBraneStudio as IDE with remote debugging. Lua itself is instanced in a persistent Application. Te controlflow is
- a persistent application which
- has a thread which
- executes lua machine
This thread can by remote control be forced to start/stop the Lua machine or to start/stop the machine with remote debugging.
NOW: if the script in the Lua machine creates additional lanes, stopping the Lua machine sometimes refuses to work. Especially when debugging is set to debug a lane and not the main thread. Maybe our approach to stop the luamachine is also wrong.
So the question could be: If you create a lua machine the simple way:
L=lua_open();
luaL_loadfile(L,scriptpath);
lua_pcall(L,0,0,-1)
and the script creates lanes (out of your control) and runs forever, how would you stop the machine?
We do this by inserting a hook
lua_sethook(L,lstop,LUA_MASKCALL|LUA_MASKRET|LUA_MASKCOUNT,1);
with
static void lstop(lua_State *L, lua_Debug *ar)
{
luaL_error(L, "!STOPPED!");
}
but maybe you have some better suggestion?
I also should mentions, this all is with luajit on an ARM system.
from lanes.
I think that just issuing an error is not enough to cleanup everything. Did you try forcing a full gc cycle after the pcall? This should cleanup everything created inside your script (besides globals and registry contents of course). Why can't you just close the state? That would gc everything and terminate the lanes.
from lanes.
Ok, this was just the short code snip (there are much more resources aside to Lua managed by the application). Full code is
int CLua::Stop(void(*killfunc)(void))
{
lua_sethook(L,lstop,LUA_MASKCALL|LUA_MASKRET|LUA_MASKCOUNT,1);
if(killfunc) killfunc();
_thread->join();
_thread=0;
if(L)
{
lua_gc(L, LUA_GCCOLLECT, 0);
lua_close(L);
}
L=0;
return 0;
}
Killfunc normally provides an Event to get Lua-Application out of GetEvent() loop.
from lanes.
Since you are closing the state, it should gc all the lanes and forcefully terminate them even if stuck in a blocking linda operation after a suitable timeout. (see shutdown_timeout in the documentation). So I'd say if you wait a little bit, you should see all lane threads disappearing from the process.
from lanes.
In fact, I've traced a bit (mainly to remember how it works), and when you lua_close the state, garbage collection invokes selfdestruct_gc, which cleans up everything, gracefully at first, then forcefully. So when lua_close() returns, there should be no lane running. At least that's what I observe with a small test that launches a lane doing a busy-loop, and closing the state before the lane ends (tested with Lua 5.4 on windows 10 64 bits).
from lanes.
Related Issues (20)
- ld: library not found for -lgcc_s.10.4 HOT 1
- How to use deep_test.c? HOT 3
- make[1]: *** [errhangtest] Segmentation fault: 11 HOT 1
- hook cancel test fails with 3.15.0 HOT 6
- Symbol not found: _LG_cancel_test HOT 5
- Each treADS created increases memory and cannot be freed by lua_close(L) after completion HOT 1
- Rockspec for all versions need to update the source url away from using the git:// prefix, which is being deprecated by Github HOT 10
- Cannot use DeepPrelude, HOT 1
- Suggestion: use lua_objlen to get size of userdata for __lanesclone HOT 6
- New release? HOT 7
- Is it possible to make lanes lanes 3.15.1 work with luajit 2.0.4 ? HOT 1
- Issue compiling when using Moonjit 2.3? HOT 8
- module 'lanes.core' not found HOT 1
- . HOT 1
- Error when running inside Docker container without sys_nice HOT 8
- Sometimes segmentation fault with Pallene? HOT 2
- In comparison.html, lanes.new() does not exist. HOT 1
- Use LuaRocks to install with HAVE_LANE_TRACKING HOT 1
- luajit+lualanes,Program crashed in ARM32 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lanes.