Saturday, February 27, 2010

SEMAPHORES IN ADA

THE PROBLEM OF SYNCHRONISATION

Often there are occasions when events must happen in a certain order ! specifically ....

(1) Serialisation: Event A must happen before Event B.
(2) Mutual exclusion: Events A and B must not happen at the same time.

In concurrent programming every process is fighting for time and resource thus in perspective of the above, order must be restored to this apparent chaos. One rather interesting way is to use semaphores.

Semaphores were invented by the Dutch computer scientist Edsger Dijkstra (EWD 74).

A definition will be, a non-negative integer-valued variable that can only be acted upon by two procedures: sem_wait and sem_post

These operations are defined (for a semaphore s) as:

sem_wait(P)
if s>0 then set s:=s-1 and allow task to proceed else suspend task

sem_post(V)
set s:=s+1

For a synchronisation where each process waits for the other, synchronous synchronisation will be done using 2 semaphores, as;


TRYING IN ADA 2005

Trying the scenario in Ada 2005, where Task A and Task B are defined as

Task A : printing 'A' 5 times
Task B : printing 'B' 5 times

yields the following results, the output strictly interleafs on all ocassions,


however the slicing is of 2 rounds of each task at a time.( i.e. 'AA' , 'BB' ....). This slicing can be tailored with scheduling policies.

REFERENCES
(1) Concurrent and Real Time Programming in Ada
(2) Semaphore construction
(3) http://code.google.com/p/ada-simple/

HELLO WORLD IN ADA 2005

HELLO ADA !

I should not be writing this article ! ...... however, trying out very simple programs in Ada 2005 made me realise how I have lost touch of the syntax etc !

Ada is a high level language which is a favourite for safety critical and real time systems. Trying out the 'Hello, World' in Ada,


The syntax has a 'pascal like' sing to it, Ada program files have extensions adb or ads. The compiler used for Ada is GNAT (which is a part of gcc).

Compilation creates 3 more files.

Running the program,



Monday, February 22, 2010

A SIMPLE EXAMPLE WITH PYCHECKER

BEGINNING TESTING !

Trying out this tool for python testing .... pychecker on program e.py,



The testing software identifies that sum 'shadows builtin' , thus changing name of the function from sum to summation.


.... rectifies the Warnings !

REFERNCES

(1) Pychecker
(2) Beginning Python : From Novice to Professional

Friday, February 19, 2010

DABBLING WITH BASH -1

DABBLING WITH BASH - 1

BASH (Bourne Again SHell), the name seemed to echo between 'Bashing' to 'Bourne Trilogy'. The command line for nearly all *nix Operating Systems is actually a programming language !

I am working on version 4.0.33


1)The Hello World Program

1a) from command line

1b) from script


1c) 'Exotic' Hello, World(s)

This program prints Hello and the first command-line argument


2)Counting from 1 to 10



3)Evaluating the squares


4)Some Arithmetic


Sunday, February 14, 2010

CHECKING FOR OPENGL RENDERING IN UBUNTU

CHECKING FOR OPENGL RENDERING !

Details about rendering and also the graphics-card can also be obtained by the command, glxinfo | grep render