SEG3550 - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

SEG3550

Description:

Between June 1985 and January 1987, a computerized radiation therapy machine ... Concurrent programming errors played an important ... Just like the DOS age. ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 20
Provided by: wind471
Category:
Tags: dos | seg3550

less

Transcript and Presenter's Notes

Title: SEG3550


1
SEG3550
  • Introduction to
  • Concurrent Programming in Java

2
Introduction
  • Between June 1985 and January 1987, a
    computerized radiation therapy machine called
    Therac-25 caused six known accidents involving
    massive overdoses with resultant deaths and
    serious injuries.
  • Concurrent programming errors played an important
    part in these six accidents.

3
Advantages of Concurrency
  • For programs that interact with the environment
    to control some physical system, the parallelism
    and concurrency can be reflected in the control
    program structure.
  • For example, a video on demand system that
    receiving data from the network and playing the
    movie. A matching server that receives many
    clients requests and matches the requests at the
    same time.

4
Advantages of Concurrency
  • Speed up response to user interaction by
    off-loading time-consuming tasks to separate
    processes.
  • Throughput can be improved by using multiple
    processes to manage communication and device
    latencies. For example, network and disk access
    are slow compared to the processor speed.

5
Whats a process?
  • A process is the execution of a sequential
    program.
  • The state of a process at any point in time
    consists of the values of explicit variables,
    declared by the programmer, and the implicit
    variables such as the program counter and the
    content of data/address registers.

6
Process execution
  • As a process executes, it transforms its state by
    executing statements.
  • Each statement consists of a sequence of one or
    more atomic actions that make indivisible state
    changes.
  • Each action causes a transition from the current
    state to the next state.
  • The order in which actions are allowed to occur
    is determined by a transition graph that is an
    abstract representation of the program.

7
State machine
  • Consider the state machine for a light switch.
    Two actions on and off can operate on the
    light switch.
  • Switch( on-gtoff-gtSwitch).
  • on causes a transition from 0 to 1.
  • off causes a transition from 1 to 0.

8
State machine of a traffic light.
  • TRAFFICLIGHT
  • (red-gtorange-gtgreen-gtorange-gtTRAFFICLIGHT).

orange
red
green
0
1
2
3
orange
9
Sequential Programming
  • Traditional sequential programming
  • Activities (procedures) are executed one after
    the other in a fixed order determined by the
    program and its inputs.
  • The activities are not overlapped in time with
    another.

10
Concurrent Programming
  • Concurrent programming
  • In concurrent programming, the execution of a
    concurrent program consists of multiple processes
    at the same time.
  • Interleaving the concurrent execution does not
    require multiple processors.
  • Interleaving instructions from multiple processes
    on a single processor can be used to simulate
    concurrency.

11
Process in an OS point of view.
  • A process in an operating system is a unit of
    resource allocation both for CPU time and for
    memory.
  • A process in OS is represented by its code, data,
    and the state of machine registers.
  • Each process in an operating system has its own
    address space and some special action must be
    taken to allow different processes to access
    shared data.

12
OS Process
  • The trading operating system process has a single
    thread of control. Just like the DOS age.
  • Modern operating systems like Windows NT allows
    light weighted processes or threads for internal
    concurrency.
  • A Process differs from a thread in such a way
    that an OS process has a data and a code segment
    however, it has multiple stacks for each thread.

13
OS Process Thread
14
Threading in Java.
  • The operations to create and initialize threads
    and to subsequently control their execution are
    provided by the Java class Thread in the package
    java.lang.
  • The program code executed by a thread is provided
    by the method run().
  • Since Java does not support multiple inheritance,
    we can implement the Runnable interface.

15
Extending the Thread Class.
  • Class MyThread extends Thread
  • Public void run()
  • Put your code here.
  • Thread a new MyThread()

16
Implementing the Runnable
  • Class MyRun implements Runnable
  • Public void run
  • ..
  • Thread b new Thread(new MyRun())

17
Thread Life Cycle
  • Once created, start() causes a thread to call its
    run() and executes it as an independent activity.
  • A thread terminates when the run() method returns
    or when it is stopped by stop(). A terminated
    thread cannot be restarted and it will be
    collected by the garbage collector.

18
Thread Life Cycle
  • The predicate isAlive() returns true if a thread
    has been started but not yet terminated.
  • When started, a thread may be currently running
    on the processor, or it may be runnable but
    waiting to be scheduled. A running process may
    explicitly give up the processor using yield().

19
Thread Life Cycle
  • A thread may be non-runnable as a result of being
    suspended using suspend(). It can be made
    runnable again using resume().
  • Sleep() causes a thread to be suspended for a
    given time and then automatically resume.
Write a Comment
User Comments (0)
About PowerShow.com