Saturday, 21 November 2015

Message Passing


Introduction: -
  • First effort- message passing among concurrent task by Brinch Hansen (1978) and Hoare (1978)
  • Developed a technique for handling the problem of what to do When multiple simultaneous requests were made by other tasks to communicate with a Given Task
  • Some form of non determinism which required to Provide fairness in choosing among Those requests.
  • Fairness: - the requester are provided at equal chance of communicating with a Given Task
  • Guarded commands: - Non deterministic constructs for statement levelcontrol. Dijkstra 1975th
  • basis of the construct.
The concept of synchronous message passing: -
  • Either synchronous or asynchronous.
  • Synchronous: - tasks are Often busy and busy When They Can not Be interrupted by other units
  • EC A and B are in execution and if A wishes to send message to B That would disrupt B's processing (current)
  • Alternative is to Provide a linguistic mechanism did Allows a task to specify other task When its ready to receive messages
  • Task can be designed so it can suspend its execution did at some point it is idle or Either Because Because it needs information from another unit before it can continue
  • some cases sit and wait: - EC, A is waiting for a message at the TimeTask B sends That message, the message can be Transmitted.. It is called Rendezvous
  •  Rendezvous: - Occur Only When Both sender and receiver want it to happen. Can Be Transmitted in Either or Both directions. 
  • Cooperation and Competition Synchronization can be handled conveniently handled with message passing model.





Protected by Copyscape Online Plagiarism Scanner

Threads

Introduction: -

  • concurrent units in Java methods named run.
  • Code can be in concurrent execution with other search methods and with the main method.
  • Process in Which the run methods execute is called a thread.
  • Lightweight task
  • They all run in the same address space.
  • Different from Ada Tasks-> heavyweight threads.
2 ways: -
  • To define a class with Run Method 
  • define a subclass of the predefined class Thread and override its run method
  • if a new subclass has a Necessary natural parent then Defining it as a subclass of the thread will not work.
  • In search situation we define a sub class inherits from its natural parent did and implement the Runnable interface.
Runnable: -
  • Provides Run Method Protocol
  • any class implements Runnable must define did run
  • An Object of the class implements Runnable That is passed to the thread constructor
  • Ada - Tasks Can Be Either actors or server task and communicate with eachother through accept clauses
  • Java methods are run all actors
  • Except for the join method and through shared data.
 The thread class: -
  • not the natural parent of any OtherClass 
  • Provides some services for its subclasses
  • not related in any natural way to Their computational purposes 
  • only OtherClass available for creating concurrent Java programs
  • includes 5 constructors and a collection of methods and constants
  • Run Method Describes the action of the thread
  • Always overriden by subclasses of threads
begin(): -
  • starts its thread as a concurrent unit by calling its run ();
  • call to start is unusual in fact, control returns immediately to the caller Which then Continues its execution in parallel with the newly started run ().
  • EC., 
                 class MyThread extends Threads
                  {
                  public void run () {} ..................
                  }
                 ......................................
                 Thread Myth = new MyThread ();
                 MyTh.start ();
  • When An Application Program Execution begins a new thread is Treated and main is called.
  • All Java Application Program runs in threads 
  • When a program has multiple threads - schedule gives equal size time slices to each thread in round-robin fashion ready Assuming all of thesis have the same priority
  • Provides several methods for controlling the execution of threads
  • yield () - no parameters; - a request from the running thread to surrender the processor voluntarily; - thread is put immediately into the task ready queue making it ready to run; - if there are no other ready threads with priority higher than one just yielded the processor so it may be the next thread to get the processor.




Protected by Copyscape Online Plagiarism Scanner

Functional Programming

Functional Programming: -

  • Languages- Pascal, C, Modula 2, Ada, are imperative languages ​​Because basic construct is a command
  • Heavily Influenced by Von Neumann architecture - includes a store (memory), on instruction used to identify the next instruction to be fetched from store 
  • computation model has control structures did Determine the sequencing of instructions- use assignments to make incremental modifications to the store.
Properties (Imperative Languages): -
  • Principal operation- assignment of values ​​to variables
  • programs are command oriented-> They carry out algorithms with statement level sequence control, selection and repetition Usually by
  • Programs are organized as Blocks-> DataControl is dominated by scope rules
  • computing is done by effect (changes to the store)
Computing: -
  • Intrinsic to imperative programming plays havoc with some of the mathematical properties- essential to prove the correctness of programs.
  • Example: - Is addition commutative Inn on imperative program, Doesburg write (a + b) always produce the same value as write (b + a).  
                                                            Most likely give different results for the two versions of this program. DEPENDING on the order of evaluation of expressions
  • Anomaly is Caused by the side effects in the expression being Evaluated 
  • Programming by effect lies at the heart of imperative programming.
  • If we depend on imperative programs we must discard many of the basic properties of mathematics (associative, commutative, law of addition and multiplication and the distributive law for multiplication over addition.
Functional Programming: -
  • Provides paradigm of alternative notion of programming 
  • Avoids the problem of side effects
  • Functional languages ​​Concerned with the Data Objects and value instead of variable
Values: -
  • Bound with identifiers
  • Once made thesis bindings can not change
  • principal operation is function application
Functions: -
  • Treated as first class objects 
  • May be stored in data structures.
  • passed as parameter
  • returned as function results
  * Functional language supplies primitive functions
  * Programmer uses function constructors to define new functions 
  * Program Execution is by evaluation of expression 
  * Sequence Control depends on selection and recursion 

Pure Functional language: -
  • No assignments language 
  • Values ​​are Communicated by the use of parameters to functions.
  • thesis restrictions enforce a discipline on the programmer did Avoids Side Effects
  • Functional languages ​​- referentially transparent
Principle of Referential Transparency: -
  • value of the function is Determined by the values ​​of its arguments and the context in Which the function application Appears.
  • It is independents of the History of the execution
  • Evaluation of a function with the same argument Produces the same result every time it is invoked
  • An expression will produce the same value each time it is Evaluated in a Given Context
  • Guarantees the validity of the property substituting equals for equals.
LISP: - 
  • List Processing [1956]
  • started with on Artificial Intelligence Group at MIT under John McCarthy 
  • Implemented (1960) on an IBM 704 (McCarthy and his students).
  • Had the first Fortran implementation 
  • Early Example of interactive computing 
  • original development used expression S (S- symbolic language)
  • Lisp with 2M expression (intention of developing Algol like version)
  • When Lisp interpreter written in Lisp what with S Lisp expression Which Dropped 2 
  • Principle version based on Lisp 1.5 include Interlisp, FranzLisp, MacLisp, CommonLisp and Scheme
  • High level notation for selection
  • Fuctions are defined as expressions 
  • Repetitive tasks by recursions
  • Parameters are passed to functions by value
  • Program Consists -> set of function definitions Followed by a list of expression did may include function evaluation.
Scheme syntax: -
  • Scheme version chosen Because of small size and uniform treatment of functions
  • BasicObject in Scheme - S expression


Protected by Copyscape Web Plagiarism Check