Jump to content




Lua "Multitasking"


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

#1 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 16 May 2014 - 10:09 PM

Hello community,
I read a post about "How do I creat an OS?" and there was a wonderful answer by @apemanzilla. He/She talked about that an OS isn't just a GUI and a collection of programs. In his opinion an OS will need "multitasking" (There is no real multitasking in Lua for those who don't know) also. He/She said that the parallel API is too limitied also.

So I decided to start writing my own "multitasking" API. I would wonder if what I did would work, so I want to ask if anyone could "take an eye on it" and help to debug it.
Here is the code: http://pastebin.com/QacNTUW9

It would really help me if anyone of you could help me with this messy piece of code :)

~Freack100

#2 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 17 May 2014 - 08:11 AM

Good idea, I think its working, haven't tested yet, but its cool.

#3 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 17 May 2014 - 09:56 PM

No one can help me?

#4 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 17 May 2014 - 10:15 PM

View PostFreack100, on 17 May 2014 - 09:56 PM, said:

No one can help me?

We can't help you if we don't know if anything is wrong with it. It seems like you're trying to make something similar to Gopher's goroutines, or my SEE threads (I'm sure there are tons of others). From the peek I took, it looked like you have the basic idea down. Inner event loop which resumes all running task and keeps track of their event filters. It's basically identical to the parallel API except that you can add new threads to the event loop at any time.

Edited by Yevano, 17 May 2014 - 10:16 PM.


#5 augustas656

  • Members
  • 158 posts

Posted 17 May 2014 - 10:18 PM

Perhaps, something like java's threading could be implemented in lua's programming functionality. Java's threading is possibly the best multi-tasking functionality.

#6 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 17 May 2014 - 10:22 PM

View Postaugustas656, on 17 May 2014 - 10:18 PM, said:

Perhaps, something like java's threading could be implemented in lua's programming functionality. Java's threading is possibly the best multi-tasking functionality.

For the same multi-tasking as in Java, you'd need to use system threads. Since Lua is not thread-safe, this is not possible unless you run each thread in a separate Lua state. The closest you can get in pure Lua is the system I described above, which uses cooperative multitasking rather than preemptive.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users