A New Meta-Programming Technology and Its Application to the Multithreading
Dear C++ programmers. I want to introduce you my innovative integrated development environment and I believe that platform makes many contributions to the current C++ programming technology. Although this platform offers completely new programming approach, I will try to keep this article as possible as short and simple. You can find out very comprehensive documentations and introductions about the technology that is developed on the project's website. The project links are given in below.
This platform which its current name is PCYNLITX has been developed based on a new idea. This idea is to develop a software which can write codes in a collaboration with its user. By this way, pcynlitx acts as a separate intelligent actor simplifying the multi-threaded software development process. The pcynlitx is an outcome of the scientific research study that is carried out by Erkam Murat Bozkurt who is a research engineer in Istanbul /Turkey and he is a C++ programmer as well. Now, let we start to investigate why we need such a platform.
WHY WE NEED A NEW PROGRAMMING PLATFORM ?
It is a well known fact that the processing power of the computers will not increase dramatically in the next decades. This situation makes low level programming languages such as C++ more popular. However, on the contrary, to learn these languages is very difficult. Therefore, the main purpose of this research study is to develop an easy and efficient way in order to decrease the complexity that are faced on the programming with low level languages such as C++. In my research study, I have obtain that the meta-programming systems may fill the gap between the programmer and the low level languages. Moreover, it can provide well established libraries and/or tools in order to increase the programmers productivity. In the following of this article, the meta-programming technology and its advantages will be clarified. In order to do that, at first, we have to look at what is the situation on the current high level languages.
In high level languages, the interpreters translate the programmer directives to the operating system level commands and perform an abstraction between the programmer and low level operations such as memory allocation / de-allocation. However, beside their advantages, this kind of interpreters may cause significant performance loses as well. In that case, we can easily consider that a well established library which is produced by a meta-programming system can produce a similar interface without leading any performance loses. A simple illustration is given in below figure.
Basically, the meta programs are the programs that write codes. In today computing environment, meta-programs already play a crucial role on the software development process. Meta-programs include things like compilers, interpreters, type checkers, program generators, transformation systems, and program analyzers. If we look at the efficiency of the software development process, the meta-programming systems may be more efficient and productive platforms than the interpreters. Because, the codes which are the outcome of these systems still works on the operating system level. Beside to this, they may produce their codes based on standard proven code templates. In that case, a pre-built code library performs the things which are performed by the interpreters previously. In order to learn how a meta-programming system can produce code from code templates, please look the programming tutorial of the pcynlitx platform. In fact, especially on the multi-threading area, the pcynlitx platform can perform many things that can not be done by the languages in which the interpreters are used.
For simplicity, in the following of this article, I will use the term “Programmable Meta-Programming Systems” in order to indicate this new meta-programming system. However, different from the other meta-programming systems, the programmable meta programming systems such platforms that they can be programmable by their programmers. More specifically, the programmers enter their preferences about the software to be developed by means of a graphical user interface ( GUI ) and then, the these systems produce application specific libraries according to their user needs. From a different point of view, we can easily say that programmable meta-programing systems are intelligent software platforms that help the programming process. They may be consider as the virtualization of the programmers.
In essence, pcynlitx is just a particular application of this new paradigm which is applied to the multithread computing and it is an open source, free to use IDE which produces a class library for C++ multi-thread programming applications. Actually, we can consider the kernel of the pcynlitx as a separate intelligent actor determines the relation between the threads and transforms the architecture of the program before programming process.
At that point, I want to clearly indicate that the pcynlitx platform is not a threading library such as the current multi-threading tools. Instead, in each time, the pcynlix platform produces an application-specific multi-threading library. In other words, the pcynlitx platform produces a multi-threading library which is specialized its programmer needs. Now, I want to clarify that why we need an application specific library especially in multi-threading.
WHY APPLICATION SPECIFIC MULTI-THREADING LIBRARY IS NECESSARY ?
With the development of the multi-core CPUs, multi-threading is not a luxury, it is a necessary. Unfortunately, the structure of a multi-threaded program may differs according to the requirements of the application to be developed. This structural diversity increases the gab between the control functions that are used for thread management and the operating system that executes the threads. In brief, the following properties of the multi-threaded programs may varies depending on the requirements of the application to be developed.
How many thread will be created on the program ?
How many function routines ( thread function ) will be executed on the program ?
Which thread function will be executed by which thread ?
Will the threads share a common memory or variable ?
Will be there a communication between the threads ?
On the single threaded applications, we don’t face this diversity. Because, a single program flow stars from a one point and the same input always gives the same output. On the contrary, on the multi-threaded applications, there are multiple flow of execution and the scheduling of the threads are performed by the operating system. In other words, operating system gives the decision about which code section will be executed by which thread on particular time interval. In fact, the operating system switches the threads according to its job queue. Therefore, the threads are scheduled randomly. In the following of this article, I will explain why scheduling of the threads is so important.
In a deterministic multi-threading environment, on the each running of the programs, the code sections are executed exactly the same order. More specifically, in a deterministic scheduling of the threads, on each run of the programs, each code sections of the programs are executed exactly the same order. An illustration of the difference between deterministic scheduling and non-deterministic sceduling is given in below.
The Figure-A depicts non-deterministic multi-threading and on each running of the program, a different scheduling scenario has been followed. However, the Figure-B depicts deterministic multi-threading and on the each run of the program, exactly the same scheduling scenario has been followed.
In this article, it has been already indicated that the structure of the multi-threaded applications to be developed may change according to the requirements of the application. Not surprisingly, on current the multi-threading, the relation between the threads can not be strictly defined before software development process. For instance, with current multi-threading tools, you can not send a signal to a particular thread according to both its ID number and its function routine which is executed by. Therefore, in order to gain more control over the threads, we must strictly define the relation between the threads. This is the reason why we need an application specific library construction process. If the programmer defines the number of the threads and what kind of thread functions will be executed by which threads, a threading library that include control tools that are produced for a particular application structure can be produced. Then, we can directly steer a particular thread in some point of the program and we can easily determine the execution order of each code segment of the multi-threaded programs.
Actually, today multi-threading applications, the case is opposite and the scheduling of the threads are performed by the operating systems randomly. Unfortunately, the random scheduling of the threads is the biggest reason of the non-determinism on the multi-threaded programs and non-deterministic scheduling of the threads breaks down input-output determinism of the multi-threaded software. Thus, developing, debugging and testing a non-deterministic multi-threaded application is very difficult. So far, the problem on the multi-thread application development has been explained. Now, it is the time to focus the solution.
WHY PCYNLITX PLATFORM IS NECESSARY ?
In pcynlitx, the platform produces some control tools that know how many thread will be created on the program. These control tools are built with memory areas. Then, in run-time, these tools receive the ID numbers of the threads given by the operating system to the threads and match these numbers with the numbers given by the programmer to the threads. By this way, the threads can be controlled with numbers given by the programmers. More specifically, by this way, on the applications that is developed with pcynlitx, the programmers can set numbers to the threads and block and rescue the threads by means of these numbers and deterministic scheduling is achieved. In fact, the user of the pcynlitx can directly schedule the execution of the threads independently from operating system. Strictly speaking, we can easily said that pcynlitx totally solves the problems caused by the non-deterministic scheduling of the threads. In below figure, the structure of the pcynlitx application is shown.
Pcynlitx platform builds very sophisticated programming infrastructure before the programming process. For instance, if you want, you can build a smart pointer which its type is defined by you. This smart pointers are automatically shared between the threads. More specifically, the communication channels between the threads are automatically established on the library construction process. The programmer defines what kind of variables and/or objects are shared between the threads. Actually, the pcynlitx platform has many powerful property that can not be summarized in that article.
The copyright of the pcynlitx platform has been taken from the US. Copyright office and it is ready to used. It is a free software which is licensed with GNU GPLv3 free software license. I want to discuss about programmable meta programming systems and pcynlitx with everyone who interest the topic and I am always waiting your valuable decisions and/or contributions. You can read more about the project from web sites. Especially, the pdf document which is named as “Techninal_Introduction.pdf” include very comprehensive explanation about the project. You can also read the same document from the project web site directly from the link given on the documentations sections as programming tutorial.
Thank you very much for reading and Best Regards.
Erkam Murat Bozkurt
M. Sc in Control Systems Engineering. Istanbul / Turkey.