Responsiveness - One thread may provide rapid response while other threads are blocked or slowed down doing intensive calculations.There are four major categories of benefits to multi-threading:. ![]() )įigure 4.2 - Multithreaded server architecture 4.1.2 Benefits A daemon would listen at a port, fork off a child for every incoming request to be processed, and then go back to listening to the port. ( The latter is how this sort of thing was done before the concept of threads was developed. Another example is a web server - Multiple threads allow for multiple requests to be satisfied simultaneously, without having to service requests sequentially or to fork off separate processes for every incoming request.For example in a word processor, a background thread may check spelling and grammar while a foreground thread processes user input ( keystrokes ), while yet a third thread loads images from the hard drive, and a fourth does periodic automatic backups of the file being edited.This is particularly true when one of the tasks may block, and it is desired to allow the other tasks to proceed without blocking.Threads are very useful in modern programming whenever a process has multiple tasks to perform independently of the others.As shown in Figure 4.1, multi-threaded applications have multiple threads within a single process, each having their own program counter, stack and set of registers, but sharing common code, data, and certain structures such as open files.įigure 4.1 - Single-threaded and multithreaded processes 4.1.1 Motivation.Traditional ( heavyweight ) processes have a single thread of control - There is one program counter, and one sequence of instructions that can be carried out at any given time.A thread is a basic unit of CPU utilization, consisting of a program counter, a stack, and a set of registers, ( and a thread ID. ![]()
0 Comments
Leave a Reply. |