Week16 - Chapter 26 Multithreaded Programming A...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 26 Multithreaded Programming A multithreaded program contains two or more parts that can run concurrently. Each part of the program is called a thread . Each thread defines a separate path of execution. Thus, multithreading is a specialized form of multitasking. There are two distinct forms of multitasking: process based : A process is a program that is executing. This type of multitasking allows your program to run multiple programs concurrently. thread based : The thread is a small unit of code that can be executed. A single program can dispatch two or more threads that can be executed concurrently. Process based multitasking deals with the "big picture" where thread based multitasking handles the details. Multitasking threads require less overhead than multitasking processes. Processes require their own separate address spaces. Interprocess communication is expensive and limited. Context switching from one process to another is costly. Threads are lightweight in comparison. They share the same address space and cooperatively share the same process. Interthread communication is inexpensive, and context switching from one thread to the next is low cost. Multithreading allows you to write very efficient programs that make maximum use of the CPU, because idle time can be kept to a minimum. For example: In a single threaded machine, the system must wait for individual tasks to complete before moving on to the next task. This can be quite costly when the task involves waiting for user input, or writing to the printer, since the CPU sits idle during most of these processes. Multithreading enables you to gain access to this idle time. The Java Thread
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Threading is integrated throughout the Java system enabling the entire environment to be asynchronous. All of the class libraries incorporate multithreading. The non-Java single-threaded system : uses an approach called an event loop with polling . Here, a single thread of control runs in an infinite loop, polling a single event queue to decide what to do next. If the queue returns information indicating that an event has occurred (let's say data is ready to be read), then the appropriate event handler is activated. While the event handler is working, nothing else can happen in the system. If the event handler needs to wait, the system must wait. Also, this kind of process can result in one part of a program dominating the processor, thereby preventing other events from being processed.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/12/2009 for the course CS 120 taught by Professor Robertdependahl during the Fall '09 term at Santa Barbara City.

Page1 / 10

Week16 - Chapter 26 Multithreaded Programming A...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online