Letters

Dr. Dobb's Journal October, 2004


Double-Checked Locking

Dear DDJ,

Thanks to Scott Meyers and Andrei Alexandrescu for their excellent articles on the Double-Checked Locking protocol (DDJ, July and August 2004). There is another remedy for the DCLP problems they point out that is both elegant and satisfies the design constraints that lead you to use lazy instantiation with DCLP in the Singleton pattern—implement a read/write locking protocol in DCLP. The read/write protocol allows any number of threads to read a resource, but only one thread to write the resource. Readers are blocked while a writer has the resource. The DCLP implementation with a read/write lock becomes:

Singleton* Singleton::instance() {
ReadWriteLock lock;
if (pInstance == 0) {
lock.upgradeToWrite();
if (pInstance == 0) {
pInstance = new Singleton;
}
}
return pInstance;
}

Obtaining the read lock initially will likely require synchronization through a critical section, with a resulting degradation of parallelism. However, other readers are not blocked beyond obtaining the lock, unless a request for a write lock is queued. An initial flood of read requests can result in a large write queue, which will be satisfied serially, but in most situations this will be quickly resolved (if it is a problem, lazy instantiation may not have been the best choice anyway...).

The core problem with the classic DCLP seems to be that it is a readers/writers synchronization problem that has not been addressed properly. Any critical resource cannot be allowed to be written while read access is allowed.

Clyde Gerber

Clyde.Gerberlawson.com

Double Dispatch: Round 3

Dear DDJ,

I went through Nat Goodspeed's "Double Dispatch Revisited" (DDJ, January 2004) and, with some guidance from others, actually built it up step by step. The material is posted at http://rlucente.bloki.com/index.jsp?name=ddj_ddp. Approach 4 presented at this URL is good enough to write apps. Approach 5 (using a container) adds a lot of complexity. Also, the concept of a functor is not necessary in the Java world, but is very necessary in C/C++. A group of us have an entire thread on this: http:// rlucente.bloki.com/forum/messages-index .jsp?tid=79104&fid=54832. Thanks for taking the time to write this article.

Robert Lucente

rlucentepipeline.com

RFID: Coming Your Way

Dear DDJ,

There is a distinction between productive technology and unproductive technology. For example, software copy protection is a monumentally unproductive technology, and in the long run, all its proponents have to show for their efforts is the rise of Linux. The morality of software copy protection is less important than the empirical fact that it has been so consistently disastrous to its backers.

As Jonathan Erickson suggests in his November 2003 "Editorial," RFID may very well be the same kind of technology. The business rhetoric of RFID promotion is singularly devoid of any real benefit for the consumer. It is mostly about efforts to control the consumer.

Wal-Mart is one of the major proponents of RFID, and a major share of Wal-Mart's merchandise is of the kind that can also be obtained by mail order. Mail order tends to enable specialist vendors, who only deal in a narrow range of goods, but do those very well. Some of the biggest beneficiaries of mailorder are people who sell big, expensive omnipurpose machines such as computers. Let us ask which party is best positioned to make use of information technology. The big problem of mail order is in delivering orders. Given that trucks roll at 70 miles an hour, the net speed of a parcel service largely reflects the speed of sorting rather than the speed of movement. It might very well be possible to use information technology in new ways to accelerate parcel sorting. Wal-Mart's low prices are based on getting the customers to do the work of sorting. It might very well be possible to wipe out this advantage. The obvious enabling use of RFID is to enable a robot to pick objects up and set them down safely. For that, you generally don't need a fixed serial number for anything that is not custom made, and you may not even need a Universal Product Code number; you simply need a homing point, and presumably a shipment number attached to the external shipping box. If a firm had a chain of 10 warehouses, distributed nationwide, that would put practically the entire American population within 200 miles of a warehouse, and, with a reasonable amount of automation, overnight delivery by ground transportation ought to be feasible. On those terms, effective delivery time may very well be faster than going to Wal-Mart, taking other obligations into account, and the goods may be cheaper as well.

No one seems to actually like shopping at Wal-Mart. There are an immense number of derogatory stories circulating on the Internet. I've only been to Wal-Mart three times, and have found it sufficiently distasteful that I would not be inclined to go back. Wal-Mart systematically mistreats its employees in search of greater efficiency, in the tradition of Henry Ford I, and the employees naturally take their feelings out on the nearest available target—the customer. All Wal-Mart has going for it is cheapness, which is to say, a certain kind of efficiency. Paradoxically, Wal-Mart's efficiency is an obsolete kind of efficiency, resembling the automobile industry, circa 1915. They are still committed to moving physical objects, rather than information. A mail-order firm has much less need to track physical objects, simply because it doesn't move them around indiscriminately without even knowing who it is going to sell them to. When Wal-Mart comes into competition with mail-order merchants using robots effectively, Wal-Mart will sink like a torpedoed ship.

Wal-Mart is vulnerable because its business model is based around the almost total depreciation of human values. It is a kind of human robot, which is inferior to real robots and, hence, the pathological obsession with trying to track everything and everyone. Here is a story that illustrates an alternative possibility. As Robert Weisbrot tells us in Freedom Bound, on February 1, 1960, in Greensboro, North Carolina, the first sit-in of the civil rights movement was launched by four young men who had become acquainted and politicized in a haberdashery shop, of all places. The store owner had turned his business into a kind of student clubhouse, in the way used bookstore proprietors often do. Having made up their minds, the young men marched off to a bigger and more impersonal chain store—Woolworths—to put their ideas into practice.

Andrew D. Todd

adtoddmail.wvnet.edu

DDJ