Research of a multithreaded non-deterministic system model Investigación de un modelo de sistema no determinista multiproceso

Managing the systems which behaviour is non-deterministic is one of the most important problems in modern management theory. Today, systems with structural and behavioural complexity are prevalent in all areas of human activity, and therefore, their research is of the utmost importance. Such systems, as opposed to deterministic systems, are called non-deterministic. They are characterised by difficult predictable behaviour determined both by external random influences, and within the systems themselves. A clear example of a non-deterministic system is crowds of people, factories, and computer networks and systems. The problem of non-deterministic behaviour directly within the context of professional activities can be seen using an example of building syntactic analysers. The aim of the paper is to design a class of systems oriented towards supporting elements of a discrete event model. The target of research is to simulate discrete event models. The subject of research is a creation of a discrete event model based on the behaviour of an undetermined finite state automaton. During the preparation of the paper, there was developed and practically implemented an algorithm for the application, which materializes the principle of working with threads. The results obtained in the paper are aimed at solving the problem of parallel data processing based on the parallelism of NFA's (non-deterministic finite automaton) behaviour when reading the input string characters. As a result, this should have a positive impact on the regulation of the simulation processes of a non-deterministic system, increasing its efficiency and stability. In conclusion, the algorithm of the application work is disclosed and conclusions about the effectiveness and efficiency of its development are drawn.


INTRODUCTION
The problem of non-determinism directly within the professional activity framework can be seen using an example of building syntactic analysers. The first LR analysers could only perform one operation at a time. Naturally, this algorithm took a lot of time to execute the program, and this time rises exponentially depending on the quantity of parameters. In 1984, a GLR-analyser was developed to be able to process several processes in parallel. The author of this development was Masaru Tomita, a Japanese scientist. He proposed a generalised algorithm for the LR parser, which allows us, unlike its predecessor, to work with vague grammars. At the heart of his idea, there is the parallelization of stacks.
The aim of this paper is to design a class-oriented towards supporting elements of a discrete event model. The following tasks have been defined in order to achieve the set goals: 1. Analysis of the subject area. 2. Analysis and search for solutions to the objective. 3. Development of an application that implements work with data threads. 4. Analysis of results.
The target of research is a simulation of discrete event models. The subject of research is the creation of a discrete event model based on the behaviour of a non-determined finite state automaton.
The application algorithm that implements the principle of working with threads has been developed and practically implemented.
This development aims to solve the problem of parallel data processing based on the parallelism of NFA behaviour when reading the input circuit characters. As a result, this should positively impact the regulation of the simulation processes of a non-deterministic system, increasing its efficiency and stability. Any system can be described according to a number of attributes: interaction with the external environment, system structure, nature of functions, nature of development, degree of organisation, complexity of behaviour, intended purpose and many others.

Simulation modelling
Despite the variety of existing systems, most of them are complex ones. However, the description of such a system through analytical mathematical models will be rather imprecise (Dukhanov & Medvedeva, 2010). Among the simulation models, two groups of models can be distinguished: discrete-event and discrete-time models. The proper division is based on the control element. In discrete event systems it is an event, and in discrete time systems it is time. Discrete simulation models may depend on events as well as on time. In terms of the abstraction level used for the representation of the system being simulated, modelling methods are divided by: -Agent-based modelling; -Discrete event modelling; -System dynamics.
Agent-based modelling describes the behaviour of selected participants, who are called agents. People, animals, transport, companies, natural phenomena and others are considered as agents. The state of the system depends on the activities of each of the participants (Dadenkov & Kon, 2015).
System dynamics is a simulation approach that studies the behaviour of complex dynamic systems (Mikhailov, 2015). Discrete event modelling, along with system dynamics, is considered a traditional method of simulating systems. It was developed back in the 1960s by the scientist Jeffrey Gordon. His approach is to characterise a system as a sequence of individual states that are separated by time intervals. In this way, we do not see the system as a whole (rejecting the continuity of time), but as a string of states that occur depending on a clearly defined signal, i.e. time. System can make a transition from a previous state to the next one only after a certain event has occurred. The system's behaviour pattern can be described in three terms: state, action, and event. After performing some action, the system changes states. The state of the system is only able to change thus when a certain event occurs (Zimina, 2017;Martyshkin et al., 2018).
Graphically, the discrete-event model of a system can be represented as a trajectory with a slider moving along it, which sets in motion after an event that has occurred. The term "process simulation" is also used as a synonym for discrete-event simulation, but they are separated due to differences in their interpretation. Specially developed simulation modelling systems are used to simulate systems using the discrete event modelling method. They are divided into general-purpose systems and field-specific one-dimensional (specialised) systems. Field-specific simulation systems usually work with systems that have a specific specialisation in a particular field, e.g. mechanical engineering, shipbuilding, computer networks, transportation flows and road traffic, etc.) .
General-purpose systems have a basic set of tools for modelling. They are mainly involved in the modelling of mass service systems (MSS) processes Martyshkin & Yasarevskaya, 2015). Common systems such as AnyLogic, GPSS (General Purpose Simulation System), Arena are among the general purpose simulation systems. The idea of GPSS belongs to Geoffrey Gordon, the founder of the discrete simulation approach; this system is one of the first of this kind still in use today. Modelling in the AnyLogic simulation environment has significant advantages and ease of use. It stands out the following features among the advantages of this program: -The speed of development. Models are created with minimal time consumption; -Saving money; -User-friendliness of its interface; -It provides a wide range of tools for working with discrete and continuous models; -Opportunities to create interactive animation for better perception of models; -Supports model experiments; -Allows you to create models of any complexity and with any approach through a constantly updated tool base (Zimina, 2017).

Components of discrete event modelling
The following components must be defined for DES modelling: -Essence -some object that is in an active state when an event occurs in the system. -Activity -processes that take place in the course of modelling the system. -Events -phenomena that bring the system to a new state at a certain point in time.
-Resources -discrete values or objects of the material world.
-Global variables -variables without limited access. -Random number generatora sequence of numbers given at random.
-Statistical collector -an algorithm that tracks data on the state of the system and generates statistics based on it.

Finite-state automaton
The so-called "five" (Q, Σ, δ, 0, F) components are used for formal description of the automaton, where the first three components, Q, Σ, F, are sets . Q contains many states of the automaton. Σ contains many input characters or the automaton's alphabet. F is a set of assumable states of the automaton. If each of these sets is finite, the name of the automaton is finite (Vashkevich & Biktashev, 2016). The remaining two components are δ and 0. The character δ is used to denote the function of transitions, and 0 describes the initial state of the automaton, with 0 ∈ (Vashkevich & Biktashev, 2011).

Non-deterministic finite automaton
It is mentioned in foreign sources as a Non-Deterministic Finite Machine (NFM) or Nondeterministic Finite Automaton (NFA) Vashkevich et al., 2015). In many ways, the NFA definition is similar to that of a deterministic finite-state automaton. For comparison, the definitions of the DFA and NFA are comparable in Table 1. The formal definition of DFA (Vashkevich & Vashkevich, 1996;Volchikhin et al., 2013): Q is the final set of all automaton states. Σ is a finite set of characters, called the alphabet. is a transition function, where δ: Q × Σ → Q. 0 is the initial state of the automaton ( 0 ∈ Q). F is a set of finite states, where F ⊆ Q. The formal definition of the NFA: Q is the finite set of all states of the automaton. Σ is a finite set of characters called an alphabet.
-transition function, where : × → 2 . 0 is the initial state of the automaton ( 0 ∈ Q). F is a set of finite states, where F ⊆ Q.
The table shows that both automata have a similar description, except for the transition function . According to the DFA definition, the transition function of the DFA matches only one state to a pair { , }, whereas in an NFA, this condition is violated, and the pair { , } may match a set of states or be empty.

RESULTS AND DISCUSSION
A distinctive feature of a NFA is that the transition from one state to another is not clearly defined. This means that if there is a situation of alternative transitions, the automaton will make a simultaneous transition to several states under given conditions. This is the automaton's ability to process in parallel . Thus, a non-deterministic finite automaton is a generalisation of the deterministic finite automaton, because it can be in several states simultaneously . Summarising the above about the DFA and the NFA, we will present the final comparative table 2 (Martin Fowler, 2011). If several transitions can be made from one state, this automaton is called non-deterministic.
The DFA does not allow for empty transitions (without an input character).

The NFA allows for empty transitions
There is a search with a return No search with return Occupies more memory Occupies less memory If the DFA finds itself in an accepting state after reading the input string, it accepts the last; otherwise, it does not accept it.
If the NFA finds itself in at least one accepting state from the whole set of states after reading the input string, it accepts this string.
A non-deterministic finite-state automaton is the simplest discrete-event model. To present the NFA as a model, it is necessary to set its initial and final (accepting) state and define the main events and conditions for the transition from one state to another .
The NFA modelling usually takes place in two ways: 1) A table of transitions.
2) A transition diagram (transition graph) (Vashkevich, 2004;. For example, let us build NFA models based on these methods. Let us present some sequence of input tape characters that the NFA must-read. Let us take the character string {a, a, c, b, b, c} as such a sequence, which the NFA defines as the alphabet Σ. Figure 1 shows a sequence of characters in the form of an input tape (string) (Mozgovoy, 2006).  In accordance with the rules for simulation of the graphs, the automaton states were marked with circles, and the accepting state was marked with a double circle. Each state is numbered inside the circle. This NFA model has three states. The arcs showed as arrows show transitions between states as well as cyclic transitions, i.e., a transition to the same state. There are two cyclic transitions in the figure. The incoming arrow on the left indicates the initial state of the automaton. Each transition arc from the top has a designation for the character, following which the transition from one state to another is made. The transition table is a method based on the transition function = { , }, where is a state, is an input character. Therefore, each state of this NFA automaton can be described as follows.
( Convert it into a transition table (Table 3). The aim of the paper is to develop an application that, when an alternative transition occurs, would launch a new thread and continue to operate in multiple threads. In programming theory, this principle of working with data is called multithreading (Staroletov,2011;Martyshkin Alexey & Pashchenko Dmitry, 2019). By multithreading, we will mean the execution of several threads in one process. Thus, a process is implemented through the execution of threads (Kizilov et al., 2016;Kizilov et al., 2015). The advantages of multithreading applications include a significant increase in the speed at which the program is executed.
The first programs were single-processor. They were executed on single-core processors, i.e., the programme was executed in a single thread. However, users have a feeling of parallel execution of the program due to the processor's speed. This phenomenon is called the pseudo-parallel execution of threads. For true parallel execution of threads, it is necessary to have a multi-core processor, and then the division into threads takes place between the processor cores. Schematically, the work of such an application is shown in Figure 3. The process generates the main thread from which new threads are created, thus forming a hierarchy of threads. The MainThread is created within the class. A new thread t is created within this thread, which is additional to MainThread. Thread t executes the command "print y" and the main thread "print x". Both commands are executed simultaneously (Figure 4). The stages of development of a multithreaded application in C# are described. At the first stage, we dealt with the theoretical issues of the application operation. The principle of its operation is based on a discrete event model of NFA behaviour. The algorithm is then described using a block diagram describing the main steps of program execution. This is followed by the final result of the application development: its software implementation in the VisualStudio environment.
1.6. Drawing up the algorithm of the program operation The functioning principle of the algorithm is based on 3 principles: -Description of NFA behaviour; -Input tape generation; -Remembering the starting points for alternatives. Theoretical development of an algorithm describing the program operation. The model of operation of a discrete event system (NFA) is taken as a theoretical basis for development. Based on the description of NFA's behaviour, an algorithm for processing input data into output data was developed ( Figure 5). Figure 5. Algorithm for processing input data into output data

Software implementation of the algorithm
In order to realise this goal, it was necessary to perform calculations in a thread that would be within the class. In the first stage, the class in which the calculations are performed was declared ( Figure 6).  The problem with the transferred parameters using the CreateThread function was solved by bringing the method into static (Figure 8). Now there was no access error to class data, as the function was moved to the class. Figure 8. The solution of the problem with transferred parameters using the CreateThread function Thus, the resulting class looks like a complete system, inside of which there is a thread with data transferred through it. This greatly simplifies the need to search and access the necessary data since all of them are inside the class. Another advantage of the development is the ability to work with multiple threads at the same time, thus processing more data without increasing the time required to complete the process. At the same time, the user does not have the opportunity to interfere with the threads' work by using private and protected rules (Figure 9).

CONCLUSION
The subject area was investigated. An analysis of the relevant literature has shown that the issue of management of systems is relevant, as most of them are complex in structure and have ambiguous behaviour. A system can be managed by regulating the processes that take place in it. In order to put the objective of the research into practice, it was necessary to research the issue of multithreaded applications that manage data in threads. To organise work in the threads, it was necessary to declare the main thread within the class and specify the condition under which this thread creates an additional thread. The issue of division of functions between these threads was also considered to prevent conflict situations when switching between threads. Multithreaded applications do work faster indeed, but their speed is ensured by multi-core processors. Therefore, it is not appropriate to consider multithreading as a means of reducing the time it takes to execute processor commands. However, the idea of parallel execution of commands is promising for application tasks.