3threads - Introduction to Threads In traditional system,...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Threads In traditional system, each process has an address space and a single thread of control. There are situations in which it is desirable to have multiple threads of control sharing a single address space but running in quasi parallel. A file server has to block waiting for the disk; If the server had multiple threads of control, a second thread could run while the first one was blocked. The net result would be a higher throughput and better performance. It is not possible to achieve this goal by creating two independent server processes because they must share a common buffer cache, which requires then to be in the same address space. Therefore, we have threads, and sometimes it is called lightweight processes. Each thread runs strictly sequentially and has its own program counter and stack to keep track of where it is. Threads share the CPU just as processes do. Only on multiprocessor do they actually run in parallel. Threads can create child threads and can block waiting for system calls to complete, just like regular processes.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Threads Vs. Processes Computer Computer Per thread items Program counter Stack Register set Child threads State Per process items Address space Global variables Open files Child processes Timers Signals Semaphores Accounting information
Background image of page 2
Thread Usage File server example: A single thread file server: the only thread gets a request, examines it and carries it out to completion before getting the next request. The CPU is simply idle while the file server is waiting for the disk. Multiple-thread file server: Here one thread, the dispatcher, reads incoming requests for work from the system mailbox. After examining the request, it choose an idle worker thread and hands it the request. When the worker wakes up, it checks to see if the request can be satisfied from the shared block cache, to which all threads have access. If not, it sends a message to the disk to get the needed block and goes to sleep awaiting completion of the disk operation. The dispatcher in the meantime can serve other requests. Finite state machine:
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

3threads - Introduction to Threads In traditional system,...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online