Threads - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Threads

Description:

Blocked threads can be switched with one that can make progress. Multi ... Chopsticks (Resources) Eating (Performing Task) Other Problems. Excessive Threading ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 15
Provided by: dominick3
Category:

less

Transcript and Presenter's Notes

Title: Threads


1
Threads
2
Threads Increase Responsiveness and Efficiency
  • Responsiveness
  • Created and switched quicker than processes
  • Efficiency
  • Blocked threads can be switched with one that can
    make progress

3
Multi-Thread Task Tree
Single Threaded Process Task Tree
4
Reasons to Use Threads
  • Creation and switching speed vs. processes
  • Simultaneous Operations
  • Concurrency
  • Illusion of multitasking
  • Not actually more efficient
  • Multiprocessing
  • Actually Multitasking

5
Concurrency vs Multiprocessing
6
Reasons to Use Threads cont.
  • Resource Sharing
  • Static Variables
  • Memory image in physical memory
  • Modularity
  • Code in modules that work independantly of each
    other
  • Good for problem solving
  • Good for customizing general programs

7
Common Implementations
  • Operating Systems
  • Introduced to the Microsoft users with Win32
  • Increase program flexibility
  • Helpful in event driven programming
  • Web Servers
  • Handle Client requests
  • Master/Slave architecture
  • One main process, many slave threads
  • Pool Architecture
  • Set Number of re-usable threads
  • Must be tweaked

8
PROBLEMS
  • And Solutions

9
Philosophers (Threads)
Rice Bowl (Processor)
Chopsticks (Resources)
Eating (Performing Task)
DEADLOCK!!!!!!
10
Prevent Deadlocks
  • Do not hold any resources until all are free
  • Time-Out feature

11
Philosophers (Threads)
Rice Bowl (Processor)
Chopsticks (Resources)
Eating (Performing Task)
12
Other Problems
And Solutions
  • Excessive Threading
  • Program spends more time in context switches than
    executing useful code
  • Solution is Common Sense
  • Use threads only when needed
  • Impose thread creation limits

13
Other Problems
And Solutions
  • Asynchronous Threading
  • Race Conditions
  • Value of object is determined by which thread
    modifies it first
  • Solution is Semaphores
  • Create Critical sections
  • Set up flag system to only allow one thread in at
    a time.

14
Other Problems
And Solutions
  • Debugging Issues
  • Non Sequential Program Execution
  • Can no longer debug line for line
  • Decreased debugging speed may not detect
    deadlocks / race conditions
  • Solution is Time stamped Logs
  • Every thread creates an execution log with a time
    stamp followed by thread ID
  • Use consolidation program to create master log
Write a Comment
User Comments (0)
About PowerShow.com