Thread Models - PowerPoint PPT Presentation

1 / 4
About This Presentation
Title:

Thread Models

Description:

Inserts guarded yield points at regular intervals ... Case 2: Java's StringBuffer. int * SEQ p1; int * SEQ p2; p1 = p2; seqp_int p1; seqp_int p2; ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 5
Provided by: jeremy150
Category:
Tags: javas | models | thread

less

Transcript and Presenter's Notes

Title: Thread Models


1
Thread Models
  • Preemptive threads
  • Advantage Enforce fairness
  • Cooperative threads
  • Advantage Easy to understand
  • Semi-cooperative threads
  • Best of both worlds!

void thread_1(void) while (1)
list head NULL void thread_2(void) list
node mknode() node-gtnext head head
node
2
Semi-Cooperative Threads
  • How it works
  • Multiprocessor support
  • Compiler tells runtime which code segments cannot
    be run concurrently
  • Threads are scheduled accordingly
  • Forced yields ) fewer constraints

Compiler
Inserts guarded yield points at regular intervals
Loader
Verifies that yield points are placed
appropriately
Runtime
Preempts by setting flag program yields at next
point
vs.
3
Applications
  • Case 1 CCured
  • Transformation can introduce bugs
  • Case 2 Javas StringBuffer

int SEQ p1 int SEQ p2 p1 p2
seqp_int p1 seqp_int p2 p1._p p2._p p1._b
p2._b p1._e p2._e
public synchronized StringBuffer append(char ch)
ensureCapacity(count1) valuecount
ch return this
4
Building Better Threads
  • Long-term goal Make threaded programming
    simple!
  • Exploit semi-cooperative approach
  • Commit changes to shared state using simple
    operations (e.g., pointer swap)
  • Use optimistic concurrency control
  • E.g., ensureCapacity()
  • Improve communication between compiler and
    runtime system
  • Semi-cooperative threads
  • Linked stacks

Key Principle The compiler can make simplifying
assumptions on a per-program basis if it tells
the runtime system about those assumptions!
Write a Comment
User Comments (0)
About PowerShow.com