Are there differences between the terms Thread, Multithread, Async and Await?

Asked

Viewed 1,242 times

5

I asked that question here at Stack Ooverflow:

What is the solution for asynchronous PHP processes?

I did it because I wanted that in the middle of a process execution, I wanted to have a certain call of a function being executed on the other plane, without needing that the script wait for the end of the execution to be completed.

Talking to a friend about the subject of "PHP has no asynchronism", I was worried that I was confusing the use of threads asymptomatic.

I have several questions on the subject:

  • There is a relationship between threads and those asynchronous calls/processing (which usually used keywords await or async), which exist in languages such as C#, Python and Nodejs? If different, what are they?

  • What would be a multithreaded? Also has some relationship with asynchronous processing?

  • I understood right or, in these languages, the call of await or async cause the program to terminate execution, while the function continues running in the background, or actually the asynchronism means that the function will only not be executed in the code’s writing order (as in a definition of setTimeout in Javascript)?

I’m asking this because to me, which I program in PHP, it seemed to be all the same :p

1 answer

5


Thread is the mechanism defining an implementation line of the applications.

Multithread is the ability to run multiple execution lines of a process that may run parallel or appear to be running parallel.

Threads are usually only needed in fact when there is a lot of processing.

For asynchronicity to work no need to threads, although they can be used in certain circumstances to achieve the goal. Directly one thing has nothing to do with another.

To have something asynchronous needs to establish some form of task, by a mechanism ready or not.

In C# you can understand a little better the difference between a task and a thread.

Has a question that answers good parts of these things.

Asynchronicity allows the program to continue running other things while it waits for some response from another party. Usually you need this when you do IO which has a certain latency.

Unless a specific implementation defines it like this, nothing guarantees, or needs, to use thread to perform the asynchronicity.

Contrary to what many think asynchronicity does not guarantee that something runs in parallel, let alone that it performs more. On the contrary, the performance is always worse. But there may be advantage in its use because the application is not in a waiting state. If everything is done right.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.