Concurrency with Isolates in Dart PRO

Dart is a single threaded programming language. Each isolate is a unit of work. It has its own memory allocation. Sharing memory between isolates is not possible. Each isolate can pass over messages to the others. When an isolate receives a message it processes it in a way similar to events handling.

import "dart:isolate";

var product = "noname";

main() 
{
  spawnFunction(sell);
  spawnFunction(buy);
  for(var i=1;i<=10;i++)
  {
    print("market of all goods i=$i product=$product"); 
    for(var m=1;m<=1000000;m++);
  }
  for(var m=1;m<=100000000;m++);
}

sell()
{
  product = "banana";
  for(var i=1;i<=10;i++)
  {
    print("i want to sell $product i=$i");
    for(var m=1;m<=1000000;m++);
  }
}

buy()
{
  product = "tapuz";
  for(var i=1;i<=10;i++)
  {
    print("i want to buy $product i=$i");
    for(var m=1;m<=1000000;m++);
  }
}

The following video clip overviews this code sample, shows its execution and explains it.

Share:

banner for the css playlist in hebrew life michael courses for programmers

The First Steps in CSS

Learn CSS using our our videos (in Hebrew) on the CSS (he) playlist on youtube. Do it now. Do it for free.

Good Trainers Collaborate with Others

It is always essential to keep an open mind and learn from others. This applies to everyone, including teachers and especially software development trainers. Software

The Beauty of Code

Coding is Art! Developing Code That Works is Simple. Develop Code with Style is a Challenge!

Update cookies preferences