Start United States USA — software Preemptive Scheduling Coroutine Programming Language

Preemptive Scheduling Coroutine Programming Language

290
0
TEILEN

Melang is new scripting language of coroutine preemptive scheduling that is based on time slices. In this article, learn about its features and usage scenarios.
Join the DZone community and get the full member experience. The concept of coroutine must be familiar to everyone now. After all, not only LUA, Go, and Kotlin but also C++ all support coroutines. But different languages have different implementations. Such as LUA, coroutines will be scheduled when someone called yield() or resume(). A new language introduced to you today is a scripting language of coroutine preemptive scheduling based on time slices. That is, each coroutine does not need to explicitly call certain functions to give up control, but according to the weight of execution time to control whether to be suspended or run. Its name is Melang. We will discuss the following: A language must have flow control, array, dict, structure, class, etc. This is no different in Melang. We will focus on the following: In Melang, each script task is an independent coroutine, and coroutines‘ execution environments are isolated. But they can communicate with each other by the message queue functions. Let’s look at two examples: There are two script files: Then I execute the following command: After execution, you will see the screen print a and b alternately, as follows: And using top command will find out that only one process (and also only one thread) is performing these two tasks. Melang scheduling does not occur in the function mln_print, but will try to switch during the processing of each statement. We create a new script file named launcher.mln to start up a.mln and b.mln by calling function mln_eval. And then execute: The output is the same as previous example. “Reflection means that the class to be operated is known at runtime, and the complete structure of the class can be obtained at runtime and the corresponding method can be called.” – Quoted from a netizen In Melang, the concept of class is called Set, but it is more similar to the structure in C but also supports function definitions.

Continue reading...