When Threads Share
Managing shared resources with mutual exclusion
Issue: 10.4 (May/June 2012)
Author: JC Cruz
Article Description: No description available.
Article Length (in bytes): 13,519
Starting Page Number: 50
RBD Number: 10408
project10408.zip Updated: Wednesday, May 2, 2012 at 1:26 AM
Related Link(s): None
Known Limitations: None
Excerpt of article text...
Sometimes threads have to share resources when they do their tasks. So today, we look at the problems caused by shared resources. We then study the concept of mutual exclusion, and learn how it coordinates shared access. Later, we look at two Real Studio classes that provide mutual exclusion.
Threads and the Common Resource
There are many cases where threads have to use the same resource. Consider the scenario in Figure 1. Threads A and B are part of a PDF utility. Both are parsing a PDF file, compressing image data and removing unwanted metadata. Both report their progress to a common dialog view, which sports two progress bars.
Now, consider the scenario in Figure 2. In this one, threads A and B form part of a database server. Thread A monitors a network port and processes all data queries. Thread B indexes the record data at regular intervals. Both use a single database model as their common resource.
The problems of sharing
Naturally, when threads use the same resource, problems can arise, often due to threads being unaware of each other.
...End of Excerpt. Please purchase the magazine to read the full article.
Article copyrighted by REALbasic Developer magazine. All rights reserved.