Welcome to the homepage of MC# language! Some thoughts about further MC# development
MC# Project
Home page 
MC# language 
Documentation 
Publications 
 Code examples 
FAQ 

 
Downloads
MC# Programming 
System
 

 
Related links
Parallel C# 
Polyphonic C# 
SKIF Project 

 
Contacts
 Contacts 


Mono powered

Microsoft .Net powered


 
   [ Ðóññêàÿ âåðñèÿ ñòðàíèöû ]    [ Version for printing ]

Some thoughts about further MC# development

Although MC# language already has enough features necessary for creating distributed applications, there are a number of further enhancements that could be made to improve the usability of the language. It’s quite possible that some of these features we will implement already in the next version:

 

1. Generics.

 

MC# language appeared when there were no generics in C# language. That’s why the syntax of typed channels in MC# is different from the well known C# 2.0 standard for class templates (where ‘<’ and ‘>’ symbols are used). For example, currently in MC# the typical chord and movable method can be described in the following way:

 

movable mfun(Channel(int) c) {

 c.Send(1);

}

int Get() & Channel c(int x) {

 return x;

}

 

If we consider C# 2.0 syntax it will look like this:

 

movable mfun(Channel<int> c) {

 c.Send(1);

}

int Get() & Channel<int> c(int x) {

 return x;

}

 

This syntax better integrates into C# 2.0 and thus can be easier understood and accepted by programmers.

 

2. Typed bidirectional channels

 

Currently bidirectional channels are not typed in MC#, i.e. it is possible to send object of any type that implements ISerializable interface. One can only check the types of incoming objects in run-time and programmer is fully responsible for checking this:

 

BDChannel bdc = new BDChannel();

bdc.Send(0);        // Sending object of type int

bdc.Send(“string”); // Sending object of type string – no error

int x = (int)bdc.Receive();

int y = (int)bdc.Receive(); // Runtime error –  types mismatch

 

With the help of generics it is possible to create typed bidirectional channels and rely on the compiler to check the typical “Types mismatch” errors:

 

BDChannel<int> bdc = new BDChannel<int>();

bdc.Send(0);        // Sending object of type int

bdc.Send(“string”); // Sending object of type string –

                    // compile errortypes mismatch

int x = bdc.Receive();

int y = bdc.Receive();

 

3. Static movable functions and channels

 

In the current implementation all movable methods are public and cannot be static (as well as channels). This means that when you launch any movable function the “owner object” of this function is transferred to another node (and if there are some channels defined in this object then their proxies are created and passed to this node). But very often we don’t need this object at all. In such cases static movable methods and static channels is what we need:

 

using System;

 

public class HelloWorld {

 static movable SayHello(Channel<string> helloChannel) {

  helloChannel.Send(“Hello”);

 }

 

 static string WaitForGreetings() &

  static Channel<string> HelloChannel(string phrase) {

  return phrase;

 }

 

 public static void Main(string[] args) {

  HelloWorld.SayHello(HelloWorld.HelloChannel);

  Console.WriteLine(HelloWorld.WaitForGreetings());

 }

}

 

4. movable – identifier or a class?

 

From the point of view of GRID systems, where theoretically started tasks can run for a few months and some of the nodes of GRID network can just “disappear” for a long time (or forever), it is crucial to have the mechanisms of checking the statuses of launched movable methods. And there must be some mechanism that allow programmer to restart and/or stop any running movable method.

Ideally we would need to get some kind of “handler” after the launch of the movable function. Using this handler we would be able to know the status of this function (“launched”, “not launched”, “node doesn’t response”, when it was started and etc.) and if necessary perform some actions with this function (start/stop/restart). However, this would mean that movable is not the distributed analogue of void or async keyword, but either a special object that have some methods and properties! This conflicts with the tradition which says that movable methods do not return any values. However, there is a workaround for this problem if we consider that we cannot return any values from movable methods and Runtime system will do this for us.

The following example shows how it can be used:

 

using System;

 

public class Fib {

 movable computeFib(long n, Channel<long> result) {

  if (n < 30) result.Send(cfib(n));

  else {

   computeFib(n-1, c1);

   computeFib(n-2, c2);

   result.Send(Get2());

  }

 }

 

 public long Get2() & Channel<long> c1(long x) &

   Channel<long> c2(long y) {

  return x + y;

 }

 

 public long Get() & Channel<long> c(long x) {

  return x;

 }

 

 private long cfib(long n)

 {

  if (n <= 1)

   return 1;

  else

   return cfib(n - 1) + cfib(n - 2);

 }

 

 public static void Main(string[] args) {

  if (args.Length < 1)

  {

   Console.WriteLine("Usage: Fib.exe number");

   return;

  }

  int n = System.Convert.ToInt32(args[0]);

  Fib fib = new Fib();

 

  // Getting handler

  movable cfs = fib.computeFib(n, fib.c);

 

  for (int i = 0;i < 100;i++) {

  // Getting the status of the movable method

   Console.WriteLine("Movable status: " + cfs.Status);

  }

  Console.WriteLine("For n = " + n + " value is " + fib.Get());

 

  cfs.Restart(); // Restart movable method

 

  Console.WriteLine("For n = " + n + " value is " + fib.Get());

 

  cfs.Restart();

  cfs.Stop(); // Stopping launched movable method

  Console.WriteLine("Movable status: " + cfs.Status);

 }

}

 

I.e. movable in this example is both identifier (analogue of void and async) and a class.


Âåñü Ïåðåñëàâëü