wiki:ExampleProducerConsumer
close Warning: Can't synchronize with repository "(default)" (Couldn't open Subversion repository /var/repositories/svn/aadl: SubversionException: ("Failed to load module for FS type 'fsfs'", 160033)). Look in the Trac log for more information.

Producer/Consumer example

This example defines two threads that exchange data. The threads can be located on different nodes and exchange data over the network in a distributed system.

AADL model

----------
-- Data --
----------

data Alpha_Type
properties
  Data_Model::Data_Representation => integer;
end Alpha_Type;

-----------------
-- Subprograms --
-----------------

subprogram Produce_Spg
features
  Data_Source : out parameter Alpha_Type;
properties
  source_language => C;
  source_name     => "user_produce_spg";
  source_text     => ("producer-consumer.c");
end Produce_Spg;

subprogram Consume_Spg
features
  Data_Sink : in parameter Alpha_Type;
properties
  source_language => C;
  source_name     => "user_consume_spg";
  source_text     => ("producer-consumer.c");
end Consume_Spg;

-------------
-- Threads --
-------------

thread P
features
  Data_Source : out data port Alpha_Type;
end P;

thread implementation P.Impl
calls {
  P_Spg : subprogram Produce_Spg;
};
connections
  parameter P_Spg.Data_Source -> Data_Source;
properties
  Dispatch_Protocol => Periodic;
  Period            => 200 Ms;
end P.Impl;

thread Q
features
  Data_Sink : in data port Alpha_Type;
end Q;

thread implementation Q.Impl
calls {
  Q_Spg : subprogram Consume_Spg;
};
connections
  parameter Data_Sink -> Q_Spg.Data_Sink;
properties
  Dispatch_Protocol => Periodic;
  Period            => 100 Ms;
end Q.Impl;

---------
-- Bus --
---------

bus Ethernet_Bus
properties
  Deployment::Transport_API => BSD_Sockets;
end Ethernet_Bus;

---------------
-- Processor --
---------------

processor the_processor
features
  ETH : requires bus access Ethernet_Bus;
properties
  Deployment::location           => "127.0.0.1";
  Deployment::Execution_Platform => Native;
end the_processor;

---------------
-- Processes --
---------------

process A
features
  Alpha : out data port Alpha_Type;
  Beta  : in data port Alpha_Type;
end A;

process implementation A.Impl
subcomponents
  Producer        : thread P.Impl;
  Result_Consumer : thread Q.Impl;
connections
  data port Producer.Data_Source -> Alpha;
  data port Beta -> Result_Consumer.Data_Sink;
end A.Impl;

process B
features
  Alpha : out data port Alpha_Type;
  Beta  : in data port Alpha_Type;
end B;

process implementation B.Impl
subcomponents
  Consumer        : thread Q.Impl;
  Result_Producer : thread P.Impl;
connections
  data port Beta -> Consumer.Data_Sink;
  data port Result_Producer.Data_Source -> Alpha;
end B.Impl;

------------
-- System --
------------

system PC_Simple
end PC_Simple;

system implementation PC_Simple.Impl
subcomponents
  pr_A : process A.Impl {Deployment::port_number => 4001;};
  pr_B : process B.Impl {Deployment::port_number => 4002;};

  CPU     : processor the_processor;
  the_bus : bus Ethernet_Bus;
connections
  bus access the_bus -> CPU.ETH;
  data port pr_A.Alpha -> pr_B.Beta
    {Actual_Connection_Binding => (reference the_bus);};
  data port pr_B.Alpha -> pr_A.Beta
    {Actual_Connection_Binding => (reference the_bus);};
properties
  actual_processor_binding => reference CPU applies to pr_A;
  actual_processor_binding => reference CPU applies to pr_B;
end PC_Simple.Impl;
Last modified 4 years ago Last modified on 04/19/13 13:09:26