Jump to content




Need help with parallel to pause a function/coroutine while a variable is set


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

#1 cyanisaac

  • Members
  • 369 posts
  • LocationSan Diego, CA

Posted 19 July 2015 - 08:58 PM

Hello! My OS uses the parallel API to run multiple things at once (for instance, a home button bar and a shell area). I am looking for a way to be able to completely pause the execution of the shell area while my home button row does a popup application. I would like to do this in a fashion similar to the parallel API and I would like to be able to pause this thread based on a variable.

In case that sounds confusing, I'll make it less confusing: I need to pause specific threads if a variable is set true and resume them once said variable is false.


Also I have no idea how the coroutine API works that's why im using parallel pls don't kill me.

This is the code in my OS:
function backgroundProcesses()
		function flightBar()
				shell.run("/OTOS/flightBar")
		end

		function otherBackgroundProcesses()
				shell.run("/OTOS/background")
		end

		term.redirect(shellArea)
		parallel.waitForAny(flightBar, otherBackgroundProcesses)
end
This runs the background processes including my "flight bar" which is my home button row.

This is my other bit of code:
function runOTOScore()
		print("Running preliminary processes...")
		shell.run("OTOS/._preliminary")
		print("Grabbing version files...")
		fs.delete("/version")
		shell.run("pastebin get ZxBUvTSG version")
		print(shell.run("/OTOS/core"))
		os.unloadAPI("OTOS")
end
This is the thing I need to be able to pause, and have it not resume until a variable is triggered, since it contains the shell area.

If anyone can help me this would be greatly appreciated.

#2 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 19 July 2015 - 09:43 PM

Were exactly do you run the shell?

Edited by H4X0RZ, 19 July 2015 - 10:27 PM.


#3 cyanisaac

  • Members
  • 369 posts
  • LocationSan Diego, CA

Posted 19 July 2015 - 10:04 PM

View PostH4X0RZ, on 19 July 2015 - 09:43 PM, said:

Were exactly to you run the shell?

See file here: http://pastebin.com/E6vvsijn
At lines 86 and 101:
if OTOS.isLoaded then
			    shellArea = window.create(term.current(), 1, 1, 51, 18)
			    infoBar = window.create(term.current(), 1, 19, 51, 1)
			    parallel.waitForAny(runOTOScore, backgroundProcesses, fixShellArea)
else
  --Whatever not important


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 20 July 2015 - 01:37 AM

Long story short, the vanilla parallel API can't do this.

It can certainly be done, but yes, an understanding of how to manage coroutines is required. Then there's the whole matter of what to do with all the events that you aren't using to resume the "paused" coroutines (timer events in particular should ideally remain in-sync) - Dan probably implemented the best solution within multishell, which was to never pause them at all, but instead to merely deny them access to user input events when they aren't in focus. It'd be relatively easy to build a custom version of the parallel API that does that.

#5 cyanisaac

  • Members
  • 369 posts
  • LocationSan Diego, CA

Posted 20 July 2015 - 02:56 AM

Could you build one that does that? I am very unfamiliar with how coroutines work and I don't know how to disable user input to a specific parallel running process.

#6 KingofGamesYami

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

Posted 20 July 2015 - 04:28 AM

I'm probably going to screw this up somewhere, but here goes:

Spoiler

I'd not bet on this working the first time, but I'm sure you can see where I'm going with it. Coroutines aren't really very difficult to work with.

PS: You could get rid of the locals and load the above as an API





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users