Welcome Guest Search | Active Topics | Log In | Register

suspend/resume squirrel script?
#1 Posted : Saturday, June 9, 2007 11:38:12 AM(UTC)
Rank: Member

Groups: Registered
Joined: 6/9/2007(UTC)
Posts: 2

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
basically, I have the following script:

while (true)
func2(22222, 44444);
func3(1, 2);

assuming that all 3 functions are blocking and exported by my application.. how can I run the script in my application asynchronously? I want to avoid adding any commands to the script as it is user-created. I'm using sqplus if thats any help.

my current implementation places SquirrelVM::RunScript(...); in it's own thread. I suspend/resume the thread using the win32 functions (SuspendThread...) and I stop the script using KillThread. I'm pretty sure this is a very bad idea.
#2 Posted : Monday, June 11, 2007 1:41:31 AM(UTC)
Rank: Advanced Member

Groups: Registered, Administrators
Joined: 6/11/2005(UTC)
Posts: 1,059

Thanks: 0 times
Was thanked: 79 time(s) in 61 post(s)

Assuming that your function func1 etc... are implemented in C++ what you need to do is use sq_suspendvm() this function will suspend the current VM and you'll be able to resume its execution from that point using sq_wakeupvm()

for eg.

<FONT face="Courier New">int func1(HSQUIRRELVM v)
//do application specific stuff

return sq_suspendvm(v);

sq_getvmstate(v) can be used to retrieve the thred state (idle,running or suspended)

if you look a the 'base library' implementation of newthread(), suspend() and wakeupvm() you can get a more conrete example of the whole coroutine thing.

I hope this helps


Follow me on Twitter @squirrellang
#3 Posted : Wednesday, January 10, 2018 1:33:06 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/16/2016(UTC)
Posts: 5

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)

Is it possible to suspend the VM, copy the state to some external storage (for example file or db). And then load the state in some other executable and resume VM there? Will above commands work for such scenario?

#4 Posted : Friday, January 19, 2018 3:20:35 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 8/23/2014(UTC)
Posts: 116
Location: Northern Germany & Lincolnshire, U.K.

Thanks: 1 times
Was thanked: 10 time(s) in 10 post(s)
possibly, though it's not meant this way. suspend and resume is for coroutines / generators.
In theory it's possible for a single VM, but exactly this resume/suspend mechanism was intended to be able to work with SEVERAL VMs in parallel.
Serialization is tedious and squirrel compiled with garbage collector would be mandatory for that(without gc there is no way to "find" all active squirrel objects in memory properly).
In addition the friend VM/generator/coroutine mechanism makes serialization of the state almost impossible unless you manually keep track of all VMs yourself in addition to that, AND you make sure that ALL VMs are in a suspended state at that time, plus you need to properly memorize which one(s) to resume after deserialization.

It's basically going down to something like a manual core dump... Suspending the active VM(s) is just the very first basic step.
As an example: I am using several VMs in parallel when it comes to callbacks and asynchroneous events. If I would try to serialize in such a callback, I would have more than one currently active VM! Hence, I would also need to find a way to serialice the C++ call stack or find some workaround, for example to have them ALL suspend properly (unwinding the C++ Stack might be a way). Anyways it's gonna be hell.

Bottom line: There is no "clean" and proper way to serialize a "full" state unless you count in massive drawbacks or do a lot of manual serialization work, which will be way more complicated than you might expect - and you deffo need to be an expert in Squirrels' internals.
I never had the need, but I think it's possible to do at least in case you never ever create more than one VM from the host (C++ side). Just... well, I don't think it's worth the (enormous) hassle...
#5 Posted : Thursday, May 31, 2018 12:38:20 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/16/2016(UTC)
Posts: 5

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Thanks for answers.

The idea would be to build some kind of business-process engine on top of Squirrel Script. Thus the executor could be one of several executables (c++ hosts) loaded at different events into host, does some processing and at some step the state is saved back to DB.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.096 seconds.