Posts

Showing posts from 2020

Tasking and Ada Rendezvous

  Tasking and the Ada Rendezvous Multiprocessing has been a part of the Ada programming language since the language was first standardized in 1983. The original version of Ada provided active concurrency objects called tasks. Today tasks are commonly implement by Ada compilers as operating system threads, but the Ada language does not depend on operating system threading to implement tasks. The execution of an Ada program consists of the execution of one or more  tasks .  Each task represents a separate thread of control that proceeds independently and concurrently between the points where it  interacts  with other tasks. The various forms of task interaction are described in this clause, and include: ·          the activation and termination of a task; ·          a call on a protected subprogram of a  protected object , providing exclusive read-write access, or concurre...

Is Ada truly verbose?

  People who prefer programming language syntax derived from the C language have often argued that the Ada language is verbose because it uses entire words rather than punctuation. Meaning C Syntax Ada Syntax Begin a block { begin, loop End a block } end, end if, end loop, end subprogram name, end task name, end protected object name, end record Declare a function taking a single integer parameter and returning an integer value int foo (int x); function foo (x : integer) return integer; Declare a 10 element integer array indexed with the values 0 through 9 int a [10]; a : array (0..9) of integer; Write a “for” loop to sum all the elements in array a declared above. for (int I = 0; I < 10; i++) {    sum += a [i]; } for I in a’range loop    sum := sum + a (i); ...

Barber Shop Problem Implemented using Ada

In computer science, the sleeping barber problem is a classic inter-process communication and synchronization problem between multiple operating system processes. The problem is analogous to that of keeping a barber working when there are customers, resting when there are none, and doing so in an orderly manner. The Sleeping Barber Problem is often attributed to Edsger Dijkstra (1965), one of the pioneers in computer science. Problem Description: Simulate a barber shop with one barber, one barber chair and a waiting room with N chairs for waiting customers. When the barber finishes cutting the hair of one customer he dismisses the customer and goes to the waiting room to see if another customer is waiting. If the customer is waiting the barber cuts the customer's hair. If no customers are waiting the barber goes to sleep on the barber chair. The next customer to arrive must awaken the barber. If all waiting room chairs are full when a new customer arrives that arriving cus...

Producer-Consumer Patterns

Image
Producer-Consumer Patterns The Producer-Consumer pattern is classically defined as two threads or tasks coordinating their behavior through a shared fixed length buffer. The producer writes data to the buffer. The consumer reads data from the buffer. The producer must stop writing to the buffer while the buffer is full. The consumer must stop reading from the buffer while the buffer is empty. The size of the buffer is fixed and does not grow during the life of the program. The minimum size of the buffer must be one element. The maximum size of the buffer is limited only by memory constraints on the program. The classic Producer-Consumer design uses one producer and one consumer. Classic Producer-Consumer Pattern In this pattern the producer and consumer have no direct interaction. Each interacts with the fixed length buffer, allowing the two tasks to execute asynchronously until the buffer is full or empty. It is important that the producer cannot write to ...