Multitasking - PowerPoint PPT Presentation


PPT – Multitasking PowerPoint presentation | free to view - id: d027b-ZDc1Z


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation



Car Park. Lars A. Conrad-Hansen, Introduction to Multimedia Systems. Semaphores (1) ... One solution to the dining philosophers problem depends on ensuring that a wait ... – PowerPoint PPT presentation

Number of Views:69
Avg rating:3.0/5.0
Slides: 49
Provided by: KRAFT1


Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Multitasking

Multitasking Synchronization
Introduction (1)
  • There are two classes of media
  • 1) Static media do not have a time dimension,
    and their contents and meaning do not depend on
    the presentation of time. Static media include
    alphanumeric data, graphics, and still images.
  • 2) Dynamic media have a time dimension,
    and their meanings and correctness depend on the
    rate at which they are presented. Dynamic media
    include animation, audio, and video.

Introduction (2)
  • Video must be played at 25 frames/s ( or
    30 frames/s, depending on the system ) in order
    to have perceptually smooth movement.
  • Similarly, only one playback rate is
    sensible when we play audio. Playback at slower
    or faster rates will distort the meaning /
    quality of sound.
  • Since these media must be played back
    continuously at a fixed rate, they are often
    called continuous media. They are also called
    isochronous media, because of the fixed
    relationship between each media unit and time.

Introduction (3)
  • We define multimedia systems as capable of
    handling at least one type of continuous media in
    digital form as well as static media ( e.g.,
    image sound)

Classes of Multimedia Systems
  • Multimedia systems can be classified into
  • 1) Standalone systems use dedicated system
    resources. The amount of multimedia information
    may be limited and multimedia data communications
    are not supported.
  • 2) Distributed systems share both system
    resources and information resources and can
    support communication among users.

Challenges of Multimedia Computing and
  • Multimedia data have a time dimension and must
    be transmitted, processed and presented in a
    fixed rate in most applications. So, the
    multimedia computing and communications system
    must meet this timeliness requirement.
  • Multimedia applications normally use multiple
    related media simultaneously.
  • Multimedia data are data intensive, so they
    must be compressed, and high-speed communications
    networks and powerful computers are required to
    handle them.

Networked Multimedia Synchronization (1)
  • Synchronization is defined as the correct or
    desired temporal appearance (presentation) of the
    media items.

Networked Multimedia Synchronization (2)
Each Package contains a bit of information,
that tells at which time it needs to be handled !

Networked Multimedia Synchronization (3)
  • The aim of temporal synchronization
    specification is to represent all possible
    temporal relationships among media.

Networked Multimedia Synchronization (4)
  • In time-line-based temporal specification,
    the presentation time of each stream is specified
    to a common clock.

Required Synchronization Accuracy (1)
  • Synchronization can be measured by four
  • 1) Delay Measures end-to-end delay in live
    applications and response time in retrieval
  • 2) Delay jitter Measures the deviation of
    presentation time of continuous media samples
    from their fixed or desired presentation time
  • 3) Intermedia skew Measures the time shift
    between related media from the desired temporal
  • 4) Tolerable error rate Measures the
    allowable bit error rate and packet error rate
    for a particular stream in a particular
    application. There are two types of errors
  • - Bit error
  • - Packet loss

Required Synchronization Accuracy (2)
Very sensitive, since we use it every day
to Localize sounds !
Synchronization Problems
  • The clock rates at the transmitter and the
    receiver might be different. If the clock rate
    is faster at the transmitter than at the
    receiver, the transmitter sends more data than
    what the receiver can consume, causing data
    overflow at the receiver. On the other hand, if
    the clock rate is slower at the transmitter than
    at the receiver, the receiver has a
    data-starvation problem.
  • When connectionless transport protocol is used,
    packets belonging to a stream may arrive at the
    receiver out of order.
  • When multiple sources are involved, it may be
    difficult to coordinate the stream transmission
    times at different locations.
  • It is important to maintain synchronization
    during and after user interactions. F. ex., when
    a presentation is resumed after pausing for some
    time, the presentation should be resumed
    synchronously. Thus, synchronization is
    complicated by user interactions.
  • Coding / decoding times for different streams may

Mechanisms to achieve multimedia synchronization
Mechanisms to achieve multimedia synchronization
Mechanisms to achieve multimedia synchronization
  • Measures to counter delay jitter can be
    divided into two groups
  • Corrective measures do not do anything to the
    transport protocol and underlying networks. They
    try to smooth out the jitter at the destination
    before media data are presented to the user.
  • Preventive measures try to minimize delay and
    delay jitter by improving transport protocol and
    underlying networks.

Mechanisms to achieve multimedia synchronization
  • Corrective measures Buffering
  • Preventive Measures When delay jitter is
    too large, corrective measures are not very
    useful, because they require a large buffer and
    long buffering time, which is inappropriate for
    many applications.

Mutual Exclusion
  • The simplest way for two or more threads in a
    java program to interact is via an object, whose
    methods can be invoked by the set of threads.
    This shared objects state can be observed and
    modified by its methods.
  • Consequently, two threads can communicate by one
    thread writing the state of the shared object and
    the other thread reading that state.
  • Trouble !!

Mutual Exclusion, Interference (1)
  • The execution of the instructions from a set
    of threads can be interleaved in an arbitrary
    fashion. This interleaving can (and will ? )
    result in incorrect updates to the state of a
    shared object. This is called interference.

Ornamental Garden
  • To simplify the problem, the garden is
    designed so that people can enter but never leave.

Mutual Exclusion, Interference (2)
  • The general solution to the problem of
    interference is to give methods that access a
    shared object with mutually exclusive access to
    that object.
  • This ensures that an update is not interupted
    by concurrent updates !

Mutual Exclusion, Interference (3)
  • Concurrent activations of a method in Java
    can be made mutually exclusive by prefixing the
    method with the keyword synchronized.
  • Java associates a lock with every object. The
    Java compiler inserts code to acquire the lock
    before executing the body of a synchronized
    method, and code to release the lock before the
    method returns.
  • If an object has more than one method, all the
    methods should be synchronized in order to ensure
    mutually exclusive access to the state of the

Ornamental Garden
Mutual Exclusion, Interference (4)
  • Once a thread has acquired the lock on an
    object by executing a synchronized method, that
    method may itself call another synchronized
    method from the same object without having to
    wait to acquire the lock again.
  • The lock counts how many times it has been
    acquired by the same thread and does not allow
    another thread to access the object until there
    has been an equivalent number of releases.
  • This locking strategy is termed recursive
    locking, since it permits recursive synchronized

Mutual Exclusion, Interference (5)
  • Example
  • public synchronized void increment(int n)
  • if(n gt 0)
  • value
  • increment(n-1)
  • else return
  • If locking in Java was not recursive, this
    example would cause a calling thread to be
    blocked forever, waiting to acquire a lock which
    it already holds.

Monitors and Condition Synchronization (1)
  • A monitor encapsulates data, which can only be
    observed and modified by monitor access
    procedures. Only a single access procedure may
    be active at a time. An access procedure thus
    has mutually exclusive access to the data
    variables encapsulated in the monitor.
  • Monitors support condition synchronization in
    addition to ensuring that access to the data they
    encapsulate is mutually exclusive. Condition
    synchronization permits a monitor to block
    threads until a particular condition holds (such
    as a count becoming non-zero, a buffer becoming
    empty, or a new input becoming available).

A monitor is simply represented in Java as a
class that has synchronized methods.
Monitors and Condition Synchronization (2)
  • Each guarded action in the model of a monitor
    is implemented as a synchronized method which
    uses a while loop and wait() to implement the
  • Changes in the state of the monitor are
    signalled to waiting threads using notify() or

Car Park
Semaphores (1)
  • down(S) when S gt 0 do decrement S
  • up(S) increment S
  • Semaphores are usually implemented by
  • a blocking wait() as follows
  • down(S) if S gt 0
  • decrement S
  • else
  • block execution of calling
  • up(S) if processes blocked on S
  • awaken one of them
  • else
  • increment S
  • A semaphore S is an integer variable that can
    take only non-negative values. Once S has been
    given an initial value, the only operations
    permitted on S are up(S) and down(S).

Semaphores (2)
  • class Buffer
  • protected Object buf
  • protected int in 0
  • protected int out 0
  • protected int count 0
  • protected int size
  • public Buffer(int size)
  • this.size size
  • buf new Objectsize
  • public synchronized void put(Object o) throws
  • while (count size) wait()
  • bufin o
  • count
  • in (in1) size
  • notify()

Semaphores (3)
  • Implementations of semaphores usually manage
    processes, blocked on a semaphore by down(), as a
    First-In-First-Out queue (FIFO). The operation
    up() awakens the process at the head of the queue.

Semaphores (4)
  • The producer-consumer model with a bounded
    buffer is an example of a program that handles
    data items without altering them.
  • In addition, the behaviour of the producer,
    the consumer, and the buffer itself are not
    affected by the value of the items they handle.
    In other words, they do not test the value of
    these data items. The behaviour is said to be

Bounded Buffer
Deadlock (1)
  • Deadlock occurs in a system when all its
    constituent processes are blocked i.e., there
    are no eligible actions it can perform.
  • Four necessary and sufficient conditions for
    the occurrence of deadlock
  • Serially reusable resources The processes
    involved share resources which they use under
    mutual exclusion
  • Incremental acquisition Processes hold on to
    resources already allocated to them while waiting
    to acquire additional resources
  • No preemtion Once acquired by a process,
    resources cannot be preemted (forcibly
    withdrawn), but are only released voluntarily
  • Wait-for-cycle A circular chain (or cycle) of
    processes exists, such that each process holds a
    resource which its successor in the cycle is
    waiting to acquire

Deadlock (2)
Deadlock (3)
Deadlock (4)
Dining Philosophers
  • The problem each philosopher is modelled by
    the process
  • Phil (sit down ?right.get ?left.get ?eat
    ?left.put ?right.put ?rise)

  • One solution to the dining philosophers
    problem depends on ensuring that a wait-for-cycle
    cannot exist. To do so, some assymmetry is
    introduced into the definition of a philosopher.
  • Odd numbered philosopher gets right fork first
    and even-numbered philosopher gets left fork

Philosophers (fixed)
Racing conditions (1)
  • Racing conditions can occur when two or more
    processes are reading some shared data and the
    final result depends on who runs exactly when.

Racing conditions (2)
Racing conditions (3)
  • So, put the thread to sleep !

Threads (1)
Threads (2)
  • Processes are not really parallel, but
    sequential !

Threads (3)
Threads (4)
  • void interrupt()
  • First the checkAccess() method of this thread is
    invoked, which may cause a SecurityException to
    be thrown
  • It the thread is blocked in an invokation of
    wait(), join(), sleep() or methods of the Object
    class, then it will receive an InterruptedExceptio

Threads (5)
  • join()
  • Waits for this thread to die, which ensures
    sequential execution !

Threads (6)
  • Thread A joins thread B (waits for thread B
    to finish) but gets interrupted by thread C

Threads (7)
  • Thread A interrupts itself, but the interrupt
    throws first an exception when the sleep() method
    is activated, since isInterrupted() does not
    affect the interrupted status of the thread

Threads (8)
  • Here, the thread will enter everlasting
    sleep, since the interrupted() method cleares the
    interrupted status of the thread. So, unless
    another thread comes and wakes the sleeping
    thread with another interrupt(), it will sleep
    forever The sleeping-beauty phenomenon

Threads (9)
Threads (10)
Threads (11)
  • Solution F.ex. use join() on one of the
    threads prior to acquiring locks