OS Review
Download
1 / 16

OS Review Processes and Threads - PowerPoint PPT Presentation


  • 63 Views
  • Uploaded on

OS Review Processes and Threads. Chi Zhang [email protected] Process Concept. Process – a program in execution; process execution must progress in sequential fashion. A process includes program counter stack data section. Process State. As a process executes, it changes state

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' OS Review Processes and Threads' - spike


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

OS ReviewProcesses and Threads

Chi Zhang

[email protected]


Process concept
Process Concept

  • Process – a program in execution; process execution must progress in sequential fashion.

  • A process includes

    • program counter

    • stack

    • data section


Process state
Process State

  • As a process executes, it changes state

    • new: The process is being created.

    • running: Instructions are being executed.

    • waiting: The process is waiting for some event to occur.

    • ready: The process is waiting to be assigned to a process.

    • terminated: The process has finished execution.


Process control block pcb
Process Control Block (PCB)

Pointer to the next process



Context switch
Context Switch

  • When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process.

  • Context-switch time is overhead; the system does no useful work while switching.

  • Time dependent on hardware support.


System calls
System Calls

  • System calls provide the interface between a running program and the operating system.


Single and multithreaded processes
Single and Multithreaded Processes

  • Code, Data and Files are shared


Benefits
Benefits

  • Responsiveness

    • User interaction in parallel with data retrieval

  • Utilization of MP Architectures

  • Resource Sharing between Threads (vs. Process)

    • E.g. Synchronization by accessing shared data

  • Economy (vs. Process)

    • If the task is the same, why not share the code?

    • In Solaris 2, creating a process is about 30 times slower than threads. Context switch threads is about 5 times slower.


User threads
User Threads

  • Thread management done by user-level threads library

  • A blocking system call will cause the entire process to block

    OS is unaware of threads

  • The kernel cannot schedule threads on different CPUs.

  • Example: Pthread, a POSIX standard (IEEE 1003.1c) API for thread creation and synchronization.



Kernel threads
Kernel Threads

  • Supported by the Kernel

  • OS manages threads

    • Slower to create and manage because of system calls

    • A blocking system call will not cause the entire process to block.

    • The kernel can schedule threads on different CPUs.


Many to many model solaris 2
Many-to-Many Model (Solaris 2)

  • Allows many user level threads to be mapped to many (fewer) kernel threads.

    • Allows the operating system to create a sufficient number of kernel threads.


  • The thread library (user level) multiplexes (schedules) user-level threads on the pool of LWPs for the process.

  • Only user-level threads currently connected to an LWP accomplish work

  • For one process, one LWP is needed for every thread that may block concurrently in system calls for multiple I/O threads


Java threads
Java Threads user-level threads on the pool of LWPs for the process.

class Command implements Runnable {

String commandLine;

Command(String commandLine) { this.commandLine = commandLine;

}

public void run() {

// Do what commandLine says to do

// yield () the thread pause temporally

}

}


Java threads1
Java Threads user-level threads on the pool of LWPs for the process.

String line = inputStream.readLine();

int numberOfCommands = // count how many comands there are on the line

Thread t[] = new Thread[numberOfCommands];

for (int i=0; i<numberOfCommands; i++) {

String c = // next command on the line

t[i] = new Thread(new Command(c));

t[i].start();

}

for (int i=0; i<numberOfCommands; i++) {

t[i].join(); // wait until the end of t[i]

}

Also


ad