Getting Started

MC# programming language is an extension of C# language and is based on .NET platform.
This language is an adaptation of the basic idea of the Polyphonic C# language for the case
of multi-threaded distributed computations.

The novel features of the MC# are

Async- and movable methods are the only way to create and run the concurrent distributed
processes (threads). These methods are declared as

          modifiers async method_name ( arguments )
              < method_body >


          modifiers movable method_name ( arguments )
              < method_body >

Async-method call starts an execution of method body in the new thread on local machine. In contrast, by the movable method call its execution can be transferred to remote machine.

So, to print "Hello, world !" in the separate thread we can execute the following program
Note 1: async- and movable methods may not have a static  modifier):

using System;
public class   HelloWorld
  public static void Main ( String [] args )
    new HelloWorld().printHello();
  public async printHello ( )
    Console.WriteLine ( "Hello, async world :-) !" );

Channels and handlers are the tools to support the interaction between asynchronous and
movable methods. Syntactically, channels and handlers are declared using chords in the
Polyphonic C# style.In the following example, the channel sendInt for transferring single integers is defined along with the corresponding handler getInt:
handler  getInt  int ( )  &   channel  sendInt ( int  x )
{   return ( x );   }

In such declarations, handlers have the following general format:

  handler_name  return_type ( args ) 
We can also declare a channel or a group of channels without a handler. In this case, we can use values being received by the channel through the global varibles.

By the rules of correct definition, channels cannot have a static modifier, and so they are always bound to some object much in the same way as ordinary methods.

But there is some special syntax to send values by the channel and to receive a value using a handler. For example, to send an integer x by the channel sendInt we need to write

            a.sendInt ! ( x );
where a is an object for which the channel getInt has been defined. It is worth to note that we may send an arbitrary number of values through the channel:

            a.sendMultiple ! ( x1, x2, x3 );
including an empty message

            a.sendSignal ! ( );
A handler is used to receive values from its jointly defined channel (or group of channels). For example, to receive a value from the channel sendInt we need to write

int m = (int) a.getInt ? ( ); 
( Note 2:  by the rules of correct usage, we need to apply a type casting to the handlers; exceptions from this rule are the expressions like 

            Console.WriteLine ( "Result is " +   a.getInt ( ) );           
Similarly to Polyphonic C#, it is possible to define several channels in a single chord. This is a major tool for synchronizing the concurrent processes in MC#:
public handler  equals  bool ( )  &   channel   c1 ( int  x )
                                                  &   channel   c2 ( int  y )
{   if  ( x == y )  
return  ( true );
        return  ( false );

Thus, a general rule for chord triggering is the following: the body of achord is executed only after all methods declared in the chord header have been called.

One of the key feature of MC# language is that the channels and handlers can be passed as arguments to the methods (in particular, to the async- and movable methods) separately from the object to which they belong (in this sense, they are similar to the C# delegates). In this case, we must point out the types of channels and handlers in the same manner as for other arguments:
public handler  insertObject  int ( MyObject[] objects ) 
     &  channel   sendObject        ( int  n, MyObject obj )
     < chord body >
              .   .   .
        myMethod ( a.insertObject, a.sendObject );   //   method call
             .   .   .
public void  myMethod  ( handler  int  (MyObject[] )   insertObject,   //   method
                                         channel        (int, MyObject) sendObject   )  // declaration
     < method body >


Sample programs in MC#:

More examples you can find in Examples section and in the MC# distribution.

( Note 3:  in command line mode, MC# compiler is called as

            > mcsc <options> <files>

for example,

            > mcsc /r:myLibrary.dll  myProgram.mcs
            > mcsc concurrentPart.mcs sequentialPart1.cs sequentialPart2.cs
See also readme ).