Docsity

Thread Synchronization: Protecting Memory and Managing Thread Queues, Papers of Operating Systems

Partial preview of the text

Download Thread Synchronization: Protecting Memory and Managing Thread Queues and more Papers Operating Systems in PDF only on Docsity!

Processes and Threads

Max Shevertalov ([email protected]) Jay Kothari ([email protected]) CS370: Operating Systems Summer 2008

Goals

  • Process vs. Kernel Thread vs. User “Green” Threads
  • Thread Cooperation
  • Synchronization
  • Implementing Concurrency

Concurrency

  • Uniprogramming:
    • Execute one program at a time
      • EX: MS/DOS, Early Mac
    • Easier to implement, less to worry about
  • Want to execute many applications at the same time (Multiprogramming)
    • Windowing systems do not experience slowdown even if an application is processing data - EX: Unix, Linux, Mac OS X, Windows NT/2000/XP
    • Harder to implement
    • All sorts of “concurrency issues”

Concurrency Issues

• Access to resources

• CPU, Memory, I/O

• OS in charge of

coordination

• HOW???

CPU

MEM

I/O 2 I/O 3

I/O 1

P 1

P 2

P 3 P 4

Abstracting a Process

  • What is a process?

Abstracting a Process

  • What is a process?
    • Execution
    • Memory
    • Registers Inst 0 Inst 1 Inst 2 Inst 3 Inst 4 Inst 5 Inst 6 ... Instn Data 0 Data 1 ...

PC

Execution

1.Fetch at PC

2.Decode

3.Execute

4.Write Results

5.Loop

Interlacing Processes

  • Interlace with time
  • Remember:
    • Program Counter (PC), Stack pointer, Registers
  • Switching
    • Save current state
    • Load new state
  • When to switch
    • Time, voluntary yield, I/O, other concerns

P 0 P 1 P 0 P 2 P 1

Time

Protection

  • In the current scheme all processors share:
    • I/O devices
    • Memory
  • Why is that bad??

Protection

  • To protect we need to make sure that:
    • Protect Memory
      • Every process does not have access to all memory
    • Protect I/O
      • Every process does not have access to all I/O
    • Preemptive switching of processes
      • Use of a timer
      • Processes cannot disable the timer

Translations

OS Code Code Heap Stack Data Code Heap Stack Data OS Data Code Heap Stack Data Code Heap Stack Data Translation Map

  • Map virtual address space to physical address space
  • On a switch load a new translation map Translation Map

P 1

P 2

Process State

• new : process is created

• ready : process is

waiting to run

• running : instructions

are executed

• waiting : process is

waiting for an event

• terminated : process

has finished execution

new terminated

ready running

waiting

admitted exit

interrupt

scheduler dispatch

I/O or event

completion

I/O or event

wait

Creating a process

  • Process state is held in a process control block (PCB)
  • To make a new process:
    • Construct PCB
    • Set up page tables for address space
    • Copy data from parent process?
    • Copy I/O state (file handles, etc)
  • Is process == program ???

Process Collaboration

  • Hight Creation/memory Overhead
  • (Relatively) Hight Context-Switch Overhead
  • Need communication
    • Shared-Memory
    • Message Passing

Shared Memory

  • Communicate by reading/ writing to the same memory
  • Low overhead
  • Complex synchronization problems Shared Code Heap Stack Data Code Heap Stack Data Code Heap Stack Data Code Heap Stack Data Translation Map Translation Map

P 1

P 2

Shared Shared