Using Threads in Interactive Systems: A Case Study
Notes by Ben Cichy 2/98
OBJECTIVE
Examine thread usage in two systems at Xerox Parc - Cedar Programming
Environment and Global View for X Windows (GVX) - in an attempt to detect common paradigms
and common mistakes of programming with threads.
OVERVIEW
Two types of analysis - dynamic and static. Dynamic examines online
thread usage and timing data, static examines code base.
DYNAMIC ANALYSIS
Examining dynamic thread behavior revealed three classes of threads.
- Eternal - Repeatedly waiting on Condition Variables
- Worker - Performing some activity
- Transient - Forked by long-lived threads - execute
quickly and die (most numerous)
Other Notes
- No benchmark contained a thread with a forking depth greater than 2
- Over half the threads waiting on CVs timed out rather than receiving
wakeup notification
PARADIGMS
(STATIC ANALYSIS)
Classified nine paradigms for working with threads:
- Defer Work - (worker threads) - most common, used for
interrupt handlers and critical threads
- PUMPS - pipeline components - can be used to exploit
parallelism, but most often used for programming convenience
- Slack Processes - type of PUMP that adds latency to
pipeline in hopes of reducing total work done
- Sleepers & One Shots - (eternal threads) - long wait
for triggering event and then brief execution (one shots exit after executing)
- Deadlock Avoiders - (transient) - fork to avoid
violating lock order constraints or some other form of deadlock.
- Task Rejuvenators - cleanup and recovery from a crashed
thread
- Serializers - Queue + thread that does work on queue
- Concurrency Exploiters - threads that take advantage of
multiprocessors and explicit parallelism
- Encapsulated Forks - modules that encapsulate paradigm
(delayed fork / MBQueue)
ISSUES IN THREAD
USE
- Overhead Cost vs. Simplification & Concurrency
- Easy Thread Use - Sleeper, One-Shot, Pump / work
defferers
- Hard Thread Use - Concurrency Exploiters, Pumps with
timing constraints, slack processes
- Mistakes - Monitors (notify - at least one waiter wakens
vs. exactly one waiter wakens)
ISSUES IN THREAD
IMPLEMENTATION
- Spurious lock conflicts - waiting thread has higher priority than the
notifying thread.
- Priorities - system violates strict priorities.
DISCUSSION POINTS
- A third of GVX's threads weren't covered by any of their paradigms.
- Task Rejuvenation - useful?
- Hacks in Thread Usage - cycle donation (blocked thread -> thread that
is blocking it, random thread), YieldButNotToMe
- Open Issues:
- Fork Failure
- Thread Priorities and Priority Inversion
- Scheduler Quantum
- Concurrency Exploiters