About Monkey 2 › Forums › Monkey 2 Projects › PseudoThreads and PseudoParallelism
This topic contains 0 replies, has 1 voice, and was last updated by
cocon 2 years, 7 months ago.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
September 14, 2016 at 7:47 pm #3948
Testing a new concept I came up today. Currently I do not care about supporting pure native parallelism, this is mostly a “software emulation”.
Instead of running every bit of code all the time I would rather organize the execution of functionality in separate time frames where each subsystem would have it’s own relative time frame, depending on whether has critical functionality or not.
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126#Import "<std>"#Import "<mojo>"Using std..Using mojoClass PseudoThreadPublicField StartTime:IntField Interval:IntField AskToComplete:BoolProperty IsCompleted:Bool()Return completedEndPrivateField started:BoolField completed:BoolMethod Update()If completed = True ReturnIf started = FalseOnStart()started = TrueStartTime = Millisecs()EndIf Millisecs() > StartTimeStartTime = Millisecs() + IntervalIf AskToCompletecompleted = TrueOnEnd()ReturnEndOnUpdate()EndEndProtectedMethod OnStart() VirtualEndMethod OnUpdate() VirtualEndMethod OnEnd() VirtualEndEndClass PseudoThreadDirectorField Threads := New List<PseudoThread>Method AddPseudoThread(thread:PseudoThread)Threads.AddLast(thread)EndMethod UpdatePseudoThreads()Local allCompleted := FalseWhile allCompleted = FalseFor Local t := Eachin Threadst.Update()NextallCompleted = FalseFor Local t := Eachin ThreadsallCompleted = t.IsCompletedIf t.IsCompleted = False ExitNextEndEndEndClass UpdateLogic Extends PseudoThreadField counter:IntField counterLimit:IntMethod OnStart() OverridePrint("Logic PseudoThread Started")counterLimit = 20Interval = 500EndMethod OnUpdate() Overridecounter += 1Print("Updating Logic: " + counter)If counter >= counterLimit Then AskToComplete = TrueEndMethod OnEnd() OverridePrint("Logic Update Stopped")EndEndClass UpdateGUI Extends PseudoThreadField counter:IntField counterLimit:IntMethod OnStart() OverridePrint("GUI PseudoThread Started")counterLimit = 10Interval = 1000EndMethod OnUpdate() Overridecounter += 1Print("Updating GUI")If counter >= counterLimit Then AskToComplete = TrueEndMethod OnEnd() OverridePrint("GUI Update Stopped")EndEndFunction Main()Local director := New PseudoThreadDirectordirector.AddPseudoThread(New UpdateLogic)director.AddPseudoThread(New UpdateGUI)director.UpdatePseudoThreads()End -
AuthorPosts
Viewing 1 post (of 1 total)
You must be logged in to reply to this topic.