Skip to content

Basic Examples

Shane McLean edited this page Oct 13, 2017 · 3 revisions

This section will contain some basic examples, covering usage of the tuple space as a local data structure and agents as lightweight processes that access the tuple space as a shared resource.

Getting started

The projecs use the nuget packages. Please update the dotSpace libraries to the latest version. Please note that the compiled versions might not run using mono, and running on Mac or Linux might require additional setup (See below).


Example1 - Hello

This Example shows how to setup a simple application using an agent.
The initialization and startup is done in Main.cs, while the Student.cs is the agent accessing the shared resource.

Syntax

  • Using .NET type the following in the command line: Example1.exe <param>.
  • Using Mono type the following in the command line: mono Example1.exe <param>.


where <param> is a any name.


Running the program with the following parameters:

Example1.exe Turing

will give the following output:

Hello student!
Turing, you are attending course 02148

Example2 - Dining Philosophers

This Example shows how to implement a solution to the Dining philosophers problem.
The initialization and startup is done in Main.cs, while the Philosopher.cs is the philosophers/agents struggling to eat the spaghetti only using their forks.

Syntax

  • Using .NET type the following in the command line: Example2.exe.
  • Using Mono type the following in the command line: mono Example2.exe.


Running the program:

Example2.exe

will give the following output:

...
Bob: I AM EATING WITH BOTH MY HANDS: 3
Done eating: 3
Bob: I AM EATING WITH BOTH MY HANDS: 3
Done eating: 3
Bob: I AM EATING WITH BOTH MY HANDS: 3
Done eating: 3
Bob: I AM EATING WITH BOTH MY HANDS: 3
Done eating: 3
Bob: I AM EATING WITH BOTH MY HANDS: 3
Done eating: 3
Alice: I AM EATING WITH BOTH MY HANDS: 1
Done eating: 1
Homer: I AM EATING WITH BOTH MY HANDS: 5
Done eating: 5
Alice: I AM EATING WITH BOTH MY HANDS: 1
Done eating: 1
Bob: I AM EATING WITH BOTH MY HANDS: 3
Done eating: 3
Bob: I AM EATING WITH BOTH MY HANDS: 3
Homer: I AM EATING WITH BOTH MY HANDS: 5
Done eating: 5
Done eating: 3
Bob: I AM EATING WITH BOTH MY HANDS: 3
Done eating: 3
Alice: I AM EATING WITH BOTH MY HANDS: 1
Done eating: 1
Alice: I AM EATING WITH BOTH MY HANDS: 1
Dave: I AM EATING WITH BOTH MY HANDS: 4
Done eating: 4
...

Example3 - Ping Pong

This Example shows how to pass a tuple back and forth between two agents. In this case the tuple holds the string value "ping" or "pong" and the number of times the tuple has been exchanged.
The initialization and startup is done in Main.cs, while the PingPong.cs is the agent passing the message back and forth.

Syntax

  • Using .NET type the following in the command line: Example3.exe.
  • Using Mono type the following in the command line: mono Example3.exe.


Running the program with the following parameters:

Example3.exe

will give the following output:

<pong,1>
<ping,2>
<pong,3>
<ping,4>
<pong,5>
<ping,6>
<pong,7>
<ping,8>
<pong,9>
<ping,10>
<pong,11>
<ping,12>
<pong,13>
<ping,14>
<pong,15>
<ping,16>
...

Example4 - Producer Consumer

This Example show how to implement a producer and consumer agent.
The initialization and startup is done in Main.cs.forth. The program implements one producer agent in Producer.cs, and three types of consumer agents in Food.cs, Drug.cs and Any.cs.

Syntax

  • Using .NET type the following in the command line: Example4.exe.
  • Using Mono type the following in the command line: mono Example4.exe.


Running the program:

Example4.exe

will give the following output:

Alice adding items to the grocery list...
Alice adding milk(1)
Alice adding soap(2)
Alice adding butter(3)
Dave shopping 2 units of soap...
GOING SHOPPING:
Bob shopping 1 units of milk...
Bob shopping 3 units of butter...