Some Threads
The support programs just discussed are owned by the operating system. These programs execute a variety of activities from managing computer resources to providing services such as printing. If the operating system can have many independently operating components, why can't a program? One programming model splits the work off into somewhat independent tasks within the same process. This is the threads model. This is shown in the following figure, which also shows, for the last time, the daemon processes that are executing. From now on, just assume that they are there.
Threads
|
In this computing model, a program (the main thread) creates threads and these threads can also create threads if they need to. Each thread executes relatively independently from other threads.
The debugging problem here is similar to the problem of processes running on different machines. In both cases, a debugger has to intervene with anything that is executing.
In the examples used so far, each executing process and thread is doing something different and, except for when you need one thread to wait for another, it is hard to know what any thread is doing. And, the nature of these kinds of programs prevents you from running your program single-threaded; that is, having only one thing running at a time.