Article Preview
Buy Now
FEATURE
The Way of the Thread
Get started with threaded tasks
Issue: 9.5 (July/August 2011)
Author: JC Cruz
Author Bio: JC is a freelance engineering writer from North Vancouver, British Columbia. He frequently contributes articles to
Article Description: No description available.
Article Length (in bytes): 39,002
Starting Page Number: 46
Article Number: 9508
Resource File(s):
9508.zip Updated: 2011-07-05 10:42:09
Related Web Link(s):
http://docs.realsoftware.com/index.php/Thread
http://docs.realsoftware.com/index.php/Semaphore
http://docs.realsoftware.com/index.php/CriticalSection
http://docs.realsoftware.com/index.php/Mutex
http://en.wikipedia.org/wiki/Mutual_exclusion
http://en.wikipedia.org/wiki/Thread_
Excerpt of article text...
Threads serve an important role in many modern software products. So today, we look at the nature of threads and their benefits. We will study the
Thread
class, its properties and methods. We will glance at the mutex concept and learn how it interacts with a thread. Finally, we will study the basic thread cycle, plus some useful ways to manage a thread.From Process to Process
When an application launches, the first thing it does is to create a
main session (Figure 1). The main session remains active until the application gets a quit signal from the user or it runs into an unhandled exception. Both will cause the main session to terminate. But only a quit signal will make the session save its user data and state.Now the main session can spawn two or more
sub-sessions (Figure 2), each one handling a specific task. Sub-session A may present a window view through which the user interacts. Sub-session B may maintain an input/output stream to an external file. And sub-session C may connect itself to the network cloud.These sub-sessions have a couple of things in common. First, they are tightly coupled to the main session and to each other. If a sub-session took too long to complete a task, the main session will appear to have stopped. Second, sub-sessions share the same resource pool as the main session. Only the main session can request new resources from its host system.
...End of Excerpt. Please purchase the magazine to read the full article.