RTSync Tutorial 2 - An Introduction

Here we will create a simple program using RTSync. In order to program in RTSync, a knowledge of C++ is required. RTSync is not a whole language of it's own, instead it is an extension to C++.

To install RTSync, run the command “make install” after extracting the tarball.

After installing the compiler, it is time to make a program using RTSync. Here is a skeleton for the first program:

#include <iostream>
using namespace std;

void print(string &s)
{
    cout << s << endl;
}

actor A{
    init
    {
        /* nothing to do in the init block */
    }

    a()
    {
        /* print something out to the screen */
        print("Hello, world!");
    }
}

int main()
{
    /* start up the RTSync system */
    rt_start("A", "a");
}

So what does this code do? Some of the code is recognizable as C++ code. The actor block creates an actor called A with one method, a(). The init block is required for all actors, even if it does not do anything. The method a() prints out the string “Hello, world!” to the console. Note that in RTSync, methods do not have a return value. Also the print function is required since the RTSync compiler does not currently recognize cout as anything, but it will recognize print as an external function call. Also note that the comments follow the C format (/* … */) instead of the C++ format. RTSync does not currently support C++ comments.

The main function has one simple line, a call to a function rt_start(). This function is generated by the compiler and handles the internal workings of RTSync, connecting to other computers for a distributed system and beginning the real-time system. The two parameters for the function are the actor's name, and the method to call.