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.

Leave a Reply

Your email address will not be published. Required fields are marked *