Please note, this is a STATIC archive of website www.javatpoint.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
Javatpoint Logo
Javatpoint Logo

What is Concurrency?

The Dart concurrency allows us to run multiple programs or multiple parts of a program simultaneously. It executes the several instructions at the same time. Dart provides the Isolates as a tool for doing works for parallel. The concurrency makes the program highly effective and throughput by utilizing the unused capabilities of essential operating system and machine hardware.

How to achieve concurrency?

In Dart, we can achieve concurrency by using the Isolates. We have discussed Dart isolates in previous tutorial. Here we will understand the brief introduction of it. Dart isolate is a version of the thread. But there is key difference between the common implementation of "Thread" or "Isolates". The isolate works differently in comparison of Thread. The isolates are independent workers that do not share memory, but instead interconnect by passing message over channels. Since isolates completes its task by passing message thus it need a way to serialize a message.

The communication between the isolates is done by the message passing as a client and server. It helps the program to take advantage of multicore microprocessor out of the box.

Dart provides the dart:isolate package to apply the isolate in our program. It provides the solution to taking single-threaded Dart code and allowing application to make greater use of the hardware available.

Let's understand the following example -

Example -

Output:

execution from main1
execution from main2
execution from main3
execution from sayhii ... the message is :Whats up!!
execution from sayhii ... the message is :Hello!!

Output 2:

execution from main1
execution from main2
execution from main3
execution from sayhii ... the message is :Hello!!
execution from sayhii ... the message is :Welcome!!

The concept of the above code is similar to the dart isolates. If we run the above program multiple times, then output will be varied every time.


Next TopicDart Unit Testing





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA