CONCURRENT PROGRAMMING FUNDAMENTALS

 concurrency & parallelism

INTRODUCTION :-

                    The phrase "parallelism" to describe concurrent programming, where execution is truly taking place in several contexts simultaneously. Thus, parallel hardware is necessary for true parallelism. There is no semantic distinction between "quasiparallelism" of a preemptive action and real parallelism.

Concurrent system that arbitrarily flips between execution contextstimes: In both cases, the same programming strategies are applicable.It alternates between execution contexts at random intervals; in both cases, the same programming strategies are applicable.
An execution context in a concurrent program is referred to as a thread.

The operating system provides one or more processes, on top of which the threads of a specific program are implemented. OS designers frequently make a distinction between a group of light-weight processes that may share an address space and a heavyweight process that has its own address space.

Sadly, there is a lack of consistency in concurrent programming terminology among writers and languages. Many languages refer to their threads as processes. It's called tasks by Ada. Threads are the term for lightweight processes in several operating systems. The address area that lightweight processes share is referred to as a job by the Mach OS, which is the ancestor of OSF Unix and MacOS X. Certain systems create new terminology, such "actors" or "filaments," in an attempt to prevent ambiguity. We will make an effort to adhere to the definitions in the first two paragraphs and to note instances where the terminology used in specific languages or systems deviates from this usage.


THREAD CREATION SYNTAX :-
        
                Though such a static kind of concurrency is usually excessively restricted, one could conceive a concurrent programming system in which the language implementation established a fixed collection of threads. The majority of concurrent systems let programmers to add new threads while they're running. Languages and libraries differ greatly in the syntactic and semantic features. At least six typical choices exist: co-begin, parallel loops, launch-at-elaboration, fork (with optional join), implicit receipt, early reply, and (5) are the first six. Special control-flow constructs are used to delimit threads in the first two alternatives. The others declare threads with syntax that is either the same as or similar to that of subroutines.

Co-Begin:-

        In Algol 68 the behavior of a begin... end block depends on whether the internal
 expressions are separated by semicolons or commas. In the former case, we have
the usual sequential semantics. In the latter case, we have either nondeterministic or concurrent semantics, depending on whether begin is preceded by keyword par.
    begin
        a := 3,
        b := 4
    end
    par begin                # concurrent #
            p(a, b, c),
            begin              # sequential #
                d := q(e, f);
                r(d, g, h)
            end,
            s(i, j)
    end

INTERUPTS AND TIME SHARING:-
                
                        Hardware signals called interrupts allowed the activities of a central processor to be synchronized with those of the data channels. If a program P needed to read a card, the processor could initiate the read action on a data channel and start executing another program Q. Once the card had been read, the channel sent an interrupt to the central processor, which could then resume execution 
of P.

        PROCESS NETWORKS:-
                
                            The pipe construct, written as "|," allows traditional sequential programs to be combined into a concurrent program. A UNIX command of the form specifies concurrent execution of the processes P,, P;,..., P,, with the the output of process P, becoming the input of process P,,,, for 1s i< k. Such commands are referred to as pipelines. Each process in a pipeline is typically a 
program in a sequential language such as C.

                                AL process network is a generalization of a pipeline, It consists of a set at processes together with edges of the form P — Q, representing a stream flowing from process P to process Q. Each process runs concurrently with the others, at its own pace, as long as it has input. An edge P — Q therefore rep-resents an unbounded buffer into which P puts values and from whieh Q gets values. Thus, ? and Qarea producer-consumer pair.


INTERLEAVING OF THREADS:-

                        Interleaving of threads is a convenient technical device for studying the con- current execution of processes. An interleaving of two sequences ¢ and f is any sequence # formed from the events of s and f, subject to the following con- straint: The events of s retain their order in v and so do the events of t. Interleaving is based on the assumption that concurrent programs can be characterized by the relative order of events. If a and z are concurrent events, then we consider the case in which a occurs before z and the case in which 2 occurs before a, but ignore the case in which a and z occur at the same time. As the number of events on a thread increases, the number of possible inter- leavings grows rapidly. 

                            If an execution of a process A consists of two events a b and an execution of a process @ consists of three events x y z, then concurrent execution of A and Z can be studied by considering the possible interleavings:

                                            a b y y 
                                            a x b y 
                                            h y B a 
                                            Y v z a s h.
                    
                            CONCURRENT TASKS IN ADA:-

                                                    The rest of this section illustrates interleaving by considering processes in Ada, The sequential aspects of Ada are similar enough to Pascal that they will be mentioned as needed. We concentrate on programs consisting of a single procedure, with the following structure: 
                            procedure (sume) is 
                            (declarations ) 
                            begin (statements) 
                            end (mame); 
The complete sequential program  prints the string 

                              hello world 
The first line of the program, with text_io; use text_io; 

imports procedure put_line from a module text_ia, 

Modules are called packages in Ada. Except in strings, Ada does not Distinguish between uppercase and lowercase letters. Comments begin with and continue to the end of the line. Processes, called tusks in Ada, correspond to modules with their own thread of control. A task is declared in two parts, called a specification and a body.

    



Comments