Return-Path: william@bourbon.usc.edu Delivery-Date: Sun Oct 26 19:44:19 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on merlot.usc.edu X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from bourbon.usc.edu (bourbon.usc.edu [128.125.9.75]) by merlot.usc.edu (8.14.1/8.14.1) with ESMTP id m9R2iJDf012703 for ; Sun, 26 Oct 2008 19:44:19 -0700 Received: from bourbon.usc.edu (localhost.localdomain [127.0.0.1]) by bourbon.usc.edu (8.14.2/8.14.1) with ESMTP id m9R2t5xv025678 for ; Sun, 26 Oct 2008 19:55:05 -0700 Message-Id: <200810270255.m9R2t5xv025678@bourbon.usc.edu> To: cs551@merlot.usc.edu Subject: Re: CS551 final1 - flood packet Date: Sun, 26 Oct 2008 19:55:05 -0700 From: Bill Cheng Someone wrote: > I have an question on flood mechanism which is among > 1) duplicate received packet and put into each node's send() queue (so there > are n copies of the original packet) > 2) use a pointer to received packet, put the pointer into each node's send() > queue > > 2nd way is obviously scalable, light weighting and efficiency. However I > encounter memory corruption problem. > Do I have to use a lock when node's are send() by using 2nd way (pointer to > packet)? > I guess no because nobody modify the data. Is this correct? > > If no, then I probably have to add lock send(). This arises an efficiency > problem: each send() have to wait each other. > So both way have there down side. Which one is more popular design? I think you can make the 2nd way work without losing efficienty. You can use a reference count with the object. The key here is that the object is read-only (i.e., it does not change). When one sender finishes sending the data, it decrements the reference count. When the reference count reaches zero, it deletes the object. Of course, when you need to increment or decrement the reference count, you need to lock a mutex. But when you are sending data, I don't think you have to lock the object since the object never changes. Also, there is no way for the object to disappear as long as its reference count is > 0. -- Bill Cheng // bill.cheng@usc.edu