干活来袭：Effective Concurrency: Know When to Use an Active Object Instead of a Mutex
This month’s Effective Concurrency column, “Know When to Use an Active Object Instead of a Mutex,” is now live on DDJ’s website.
From the article:
Let’s say that your program has a shared log file object. The log file is likely to be a popular object; lots of different threads must be able to write to the file; and to avoid corruption, we need to ensure that only one thread may be writing to the file at any given time.
Quick: How would you serialize access to the log file?
Before reading on, please think about the question and pencil in some pseudocode to vet your design. More importantly, especially if you think this is an easy question with an easy answer, try to think of at least two completely different ways to satisfy the problem requirements, and jot down a bullet list of the advantages and disadvantages they trade off.
Ready? Then let’s begin.
I hope you enjoy it. Finally, here are links to previous Effective Concurrency columns:
Pillars of Concurrency (Aug 2007)
Much Scalability Do You Have or Need? (Sep 2007)
Critical Sections Consistently (Nov 2007)
Lock Hierarchies to Avoid Deadlock (Jan 2008)
Amdahl’s Law! (Feb 2008)
Superlinear (Mar 2008)
Linearity and the Bigger Machine (Apr 2008)
Politely (May 2008)
Locality, Minimize Contention (Jun 2008)
Concurrency-Friendly Data Structures (Jul 2008)
Many Faces of Deadlock (Aug 2008)
Code: A False Sense of Security (Sep 2008)
Lock-Free Code: A Corrected Queue (Oct 2008)
a Generalized Concurrent Queue (Nov 2008)
Parallel Performance (Dec 2008)
vs. volatile (Feb 2009)
Is the Root of All Contention (Mar 2009)
False Sharing (May 2009)
Up and Interleave Work to Keep Threads Responsive (Jun 2009)
Power of “In Progress” (Jul 2009)
for Manycore Systems (Aug 2009)
Futures to Baked-In “Async APIs” (Jan 2010)
Mutexes with Data to Prevent Races (May 2010)
Using Active Objects Instead of Naked Threads (June 2010)
33 Know When to Use an Active Object Instead of a Mutex (September 2010)