- set a timer to generate an interrupt in a given time
- before transferring to user, OS loads timer with time to interrupt
- OS decrements until it reaches 0, and then gets interrupted and OS regains control

- to gain speedup by overlapping activities or working in parallel
- to better structure an application as set of cooperating processes
- to share information between jobs

thread of control

defines where the process is currently executing (that is the PC and registers)

full process includes...

- address space (defining all the code and data pages)
- OS resources and accounting info
- thread of control

what do lightweight processes share?

- code and data (address space)
- same privileges
- share almost everything in the process

what DON'T lightweight processes share?

program counter, registers, and stack pointer

idea behind LWP

separate idea of process (address space, accounting, etc) from that of the minimal "thread of control" (PC, SP, registers)?

difference between processes and threads

process has address space and general process attributes

thread defines a sequential execution stream within a process

processes are the containers that threads run in (only one process per thread, many threads per process)

thread

- no data segment or heap
- cannot live on its own, must be inside process
- inexpensive creation
- inexpensive context switching
thread dies, its stack is reclaimed

process

- has code/data/heap and other segments
- must be at least one thread in a process
- threads within a process share code/data/heap, share I/O, but each has its own stack and registers
- expensive creation
- expensive context switching
- if a process dies, its resources are reclaimed and all threads die