Article Preview
Buy Now
FEATURE
When Threads Share
Managing shared resources with mutual exclusion
Issue: 10.4 (May/June 2012)
Author: JC Cruz
Author Bio: JC is a freelance engineering writer based in British Columbia. He frequently contributes articles to MacTech and RealStudio Developer. He was a regular on the defunct Python Magazine, and he now writes for Dr Dobbs/TechWeb. Away from the writing pile, JC spends quality time with his foster nephew, as a proper uncle should. He can be reached at anarakisware@gmail.com.
Article Description: No description available.
Article Length (in bytes): 28,167
Starting Page Number: 50
Article Number: 10408
Resource File(s):
project10408.zip Updated: 2012-05-02 00:55:02
Related Web Link(s):
http://www.rbdeveloper.com/browse/9.5/9508/
http://docs.realsoftware.com/index.php/Semaphore
http://docs.realsoftware.com/index.php/CriticalSection
http://en.wikipedia.org/wiki/Mutual_exclusion
http://en.wikipedia.org/wiki/Semaphore_
http://en.wikipedia.org/wiki/Reentrant_mutex
http://en.wikipedia.org/wiki/Critical_section
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
andB
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 commondialog view , which sports two progress bars.Now, consider the scenario in Figure 2. In this one, threads
A
andB
form part of a database server. ThreadA
monitors a network port and processes all data queries. ThreadB
indexes the record data at regular intervals. Both use a singledatabase 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.