[fpc-pascal] Acitve Object Messaging Library

Michael Van Canneyt michael at freepascal.org
Mon Apr 5 18:02:24 CEST 2010


Hello,

This looks promising.

Can you explain the similarities and differences with MPI ?

Several people have asked about MPI in Free Pascal. Maybe
this is an answer for them.

Michael.

On Mon, 5 Apr 2010, Werner Van Belle wrote:

> Hello,
>
> After the couple of questions I had about reference counting and
> cmpxchg, I can finally share what we have been working on, this would be
> the eternal gratitude part. A freepascal implementation of active objects.
>
> http://werner.yellowcouch.org/Papers/activeobjects/index.html
>
> From the abstract: Active objects seperates various tasks through means
> of a message queue whereby the queue will activate the underlying task
> whenever a new message comes in. Using this abstraction it becomes
> possible to have time speration between threads (they will not influence
> each others execution/not wait for each other), space separation
> (different tasks will not write into each others data space), scheduling
> independence (we can run multiple tasks with one, two or more
> processes), syntactical separation (each task is declared in its own
> source file) and finally lockfree programming, which thus also leads to
> a noticable lack of deadlock and race-conditions
>
> The library consists of a precompiler and a runtime. Originally, both
> were written in C++. Recently I modified the compiler to generate pascal
> code. In general, to write an active object description one writes a
> littl  file:
>
> active DemoSender
> {
>  integer tosend = 20;
>  DemoReceiver recv;
>  message startSending(DemoReceiver vrecv, integer nr);
> };
>
> active DemoReceiver
> {
>  message printNumber(integer nr);
> };
>
> This can then be compiled to a forward include, an interface include and
> an implementation include.-
>
>   aoc demo2.ao demo2.pas --pascal
>
> This generates
>
> - demo2_ifc.inc: contains the most important part of the interface
> section. It can be included in other interface sections.
> - demo2_imp.inc: contains all the function, constructor and producedure
> implementations. Can be included in -guess what- an  implementation section.
> - demo2_fwd.inc: if you need them, you get a collection of forward
> declarations. Can also be included in an interface section.
>
> Of course, the messages startSending and printNumber must be
> implemented. This is done in the file demo2.pas
>
> program demo2;
> {$MODE OBJFPC}{$H+}
> uses cthreads, sysutils, active_objects;
>
> {$include demo2_fwd.inc}
> {$include demo2_ifc.inc}
> {$include demo2_imp.inc}
>
> Function ActiveDemoSender.startSending(vrecv: DemoReceiver; nr:
> Integer): ElementResult;
> Var
>   i : integer;
> Begin
>   WriteLn(-14);
>   tosend:= nr;
>   for i := 0 to tosend-1 do vrecv.printNumber(i);
>   deactivate;
>   Result:= Done;
>   WriteLn(-15);
> End;
>
> Function ActiveDemoReceiver.printNumber(nr: Integer): elementResult;
> Begin
>   WriteLn(nr);
>   if nr = 20 then deactivate;
>   Result:= Done;
> End;
>
>
> An then of course, in the end, we want to start these two task after
> allocating them-
>
> Var
>   sender : DemoSender;
>   recv      : DemoReceiver;
> begin
>   sender:= DemoSender.Create;
>   recv:= DemoReceiver.Create;
>   WriteLn('Loaded Objects. Press enter...');
>   Readln();
>   sender.startSending(recv,100);
>   sleep(100);
> End.
>
> So, obviously a very quick example. If you are interested, it is
> probably best to read the article mentioned above and to download both
> the C++ version (it contains the compiler) and the fpc version (which
> contains the runtime) from
>
> ftp://ftp.yellowcouch.org/flow/
>
> With kind regards,
>
> -- 
> http://werner.yellowcouch.org/
>
>
>



More information about the fpc-pascal mailing list