Jump to content




Saving threads


  • You cannot reply to this topic
9 replies to this topic

#1 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 04 September 2015 - 05:11 PM

Hi!
How can I convert threads to strings or anything save-able and convert back?
Thanks!

Edited by Konlab, 04 September 2015 - 05:21 PM.


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 04 September 2015 - 05:15 PM

You can't.

#3 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 04 September 2015 - 05:20 PM

 KingofGamesYami, on 04 September 2015 - 05:15 PM, said:

You can't.
:'(
Thanks for replying

#4 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 04 September 2015 - 05:30 PM

Idea/question:
If I save all events what happened can I simulate a thread reload?
Like this:
allevents will be a global table
os.pullEventRaw:
 function os.pullEventRaw()
local event = {coroutine.yield()}
allevents[#allevents+1] = event
return unpack(event)
end
os.hibernate:
Saving allevents in ".events.log"
startup:
Declaring global allevents
If exists .events.log then queue every event in it

Can this work?

#5 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 04 September 2015 - 05:45 PM

In most cases, yes. For some stuff, no (specifically, anything that uses math.random).

#6 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 04 September 2015 - 06:12 PM

 KingofGamesYami, on 04 September 2015 - 05:45 PM, said:

In most cases, yes. For some stuff, no (specifically, anything that uses math.random).
Save all random values
(
Also I'm thinking about files
When restoring the fs api ruins it. Like if you have a file manager click the first file then delete then hibernate)
As typing i got an idea:
Or just saving all files at the beginning when turning on the computer and when restoring first restoring the original file structure then restore

Edit:
Or save when hibernating and disable fs API when restoring. But when using this make a lua app run it and delete it hibernate and crash. :( but if you do it at the beginning external editors ruin it.

Edited by Konlab, 04 September 2015 - 06:20 PM.


#7 HDeffo

  • Members
  • 214 posts

Posted 06 September 2015 - 05:04 AM

--#assume foo is the function you create the coroutine from
coroutine = string.dump(foo) --#saved as a string

coroutine = loadstring(coroutine) --#loaded as a function again again
you may also use setfenv to keep the persistence of it in terms of variables but that would take a bit more work. thats about as close as you can get to saving a thread

Edited by HDeffo, 06 September 2015 - 05:05 AM.


#8 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 06 September 2015 - 07:09 AM

Thanks for replying HDeffo, I'll try this:
Save filesystem at the beginning
Save events
Save all global variables and functions when hibernating
Save filesystem when hibernating
Restore:
Restore filesystem at the beginning
Queue all events + 1 end event
If the coroutine manager gets the end event it'll compare global variables to the saved gl. Vars and the filesystem too.
If something is missing or there are extra files it'll restore the saved filesystem when hibernating and reboot to avoid data loss

#9 flaghacker

  • Members
  • 655 posts

Posted 07 September 2015 - 08:55 PM

You should consider stuff like disk.isPresent, os.time as well.

#10 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 08 September 2015 - 12:25 PM

Yes, it's a lot of work and disk space for that little thing...





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users