Posts

Showing posts from July, 2017

An Ada Publish-Subscribe Producer-Consumer Exercise

There are many ways to express the classic producer-consumer problem in Ada. Following is a problem which illustrates some of the interesting features of Ada protected objects. Problem Statement This producer-consumer problem has several requirements: ·There shall be one producer and many consumers. ·The number of consumers shall be established at run-time through user input. ·The producer shall produce a series of random floating point numbers ·All consumers shall read each number produced by the producer exactly once. ·The producer shall not know the number of consumers The requirement that the producer shall not know the number of consumers prohibits the use of the Ada Rendezvous mechanism for direct communication between the producer and all the consumers. An alternative compliant with this requirement is to use a protected object as a shared buffer between the producer and all the consumers. In fact, the solution below uses a protected object that implements a publish-subscribe mecha…