What is a state machine?

I'm doing a tour of the site, researching about asynchronism, threads, parallelism and the like.

Upon finding this Answer, I realized that the author makes a quote regarding state machines.

I didn't quite understand what a state machine would be and what relationship it would have with asynchronism, threads and the like.

  • What would be state machine?

  • What is the relationship with the mentioned terms up?

Author: Wallace Maxters, 2017-05-29

2 answers

Asynchronism can be achieved through a state machine since it only needs to ensure that no waiting occurs while doing something potentially time-consuming, so it needs to switch the execution context between more than one part of the application.

This is an ancient and well-known technique used in various problems. It will exchange one or more certain states according to what is going on in something related to what it is control.

Even this mechanism has several ways to implement it. The way the input that causes state exchange can be obtained in several ways. A system of events indicating the change of State is quite common.

The image in the question is very illustrative of how complicated it is to control the execution flow. Follow the Indian War.

Async state machine / await

Wikipedia article .

An implementation in C # .

Detailed explanation of how c # async/await works . There are more or less examples of how the code actually looks when this engine is used. Everything there is a state machine, and what is waiting is responsible for changing the state of this machine. When there is no more waiting a different processing is executed terminating the one that started, but does not block the execution of other things. Is there a control if it can still perform something else, or whether to resume processing of what is on hold.

A example of actual code that is generated by the compiler. Simple, right?

I'll still get better.

 9
Author: Maniero, 2017-05-29 13:07:08

A state machine is a computer science term that describes a computer program. If you stop to think, a system is a set of states, for example, in the fibonacci sequence we have the sum of the last two numbers to form the next number. This machine would have an initial state:

N1: 1
N2: 1
N3: 2

The following state would be:

N1: 1
N2: 2
N3: 3

And so on. A state machine is the graphical representation of a computer program and all its states possible and is usually used to illustrate data and information flows, describing the states that happen halfway.

It has no relation to terms, not least because it is used only for illustration and diagramming. It may be that the person has used of a state machine to represent the operation of some asynchronous program or some thread .

See this link for a better reference.

 6
Author: KhaosDoctor, 2017-05-29 12:58:13