Example applications using threads(cont Adobe Page Maker(cont Dynamic scrolling Redrawing the screen as the user drags the scroll indicator -- is possible. The event-handling thread monitors the scroll bar and redraws the margin ruler ( which can be done relatively quickly) Meanwhile, the screen-redraw thread constantly tries to redraw the page and catch up. (Each user click on the scroll bar aborts the previous drawing and starts a new one. In this example, the event-handling thread can be considered as doing foreground work while the screen -redraw thread is considered the background work
11 Example applications using threads (cont.) • Adobe PageMaker (cont.) – Dynamic scrolling • Redrawing the screen as the user drags the scroll indicator -- is possible. The event-handling thread monitors the scroll bar and redraws the margin ruler (which can be done relatively quickly). • Meanwhile, the screen-redraw thread constantly tries to redraw the page and catch up. (Each user click on the scroll bar aborts the previous drawing and starts a new one.) In this example, the event-handling thread can be considered as doing foreground work while the screen-redraw thread is considered the background work
Example applications using threads(cont asynchronous processing Have a backup thread periodically saving the current user data to disk when the main thread is doing some computation peeay execution In a multiprocessor system. one thread reads in data while another thread does the computation 12
12 Example applications using threads (cont.) • Asynchronous processing – Have a backup thread periodically saving the current user data to disk when the main thread is doing some computation. • Speedy execution – In a multiprocessor system, one thread reads in data while another thread does the computation
Threads(cont Because all threads in a task share the same address space, all threads must enter a suspend state at the same time Thread functionalit thread states running, ready blocked · no suspend state thread operations spawn, block, unblock, finish thread synchronization The alteration of one resource by a thread affects other threads e.g., opening files same techniques as process synchronization
13 Threads (cont.) • Because all threads in a task share the same address space, all threads must enter a suspend state at the same time. • Thread functionality – thread states • running, ready, blocked • no suspend state • thread operations – spawn, block, unblock, finish – thread synchronization • The alteration of one resource by a thread affects other threads. – e.g., opening files • same techniques as process synchronization
Threads User Threads User Library Space Library S Kernel Kernel Kernel ace ace P (a) Pure user-level (b) Pure kernel-level (e) Combined User-level thread Kernel-level thread()Process Figure 4.6 User-Level and Kernel-Level Threads
14