Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 10.4 ('Extreme Programming')
Instant purchase and download via GumRoad!

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):

Download Icon 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 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.