[Avida-cvs] [avida-svn] r996 - in branches/coopcomm: Avida.xcodeproj source/main

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Tue Sep 26 11:16:59 PDT 2006


Author: dknoester
Date: 2006-09-26 14:16:59 -0400 (Tue, 26 Sep 2006)
New Revision: 996

Modified:
   branches/coopcomm/Avida.xcodeproj/project.pbxproj
   branches/coopcomm/source/main/cOrganism.cc
   branches/coopcomm/source/main/cStats.cc
Log:
Updated comments in cOrganism::SendMessage related to message lifetime.

Modified: branches/coopcomm/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/coopcomm/Avida.xcodeproj/project.pbxproj	2006-09-26 17:09:33 UTC (rev 995)
+++ branches/coopcomm/Avida.xcodeproj/project.pbxproj	2006-09-26 18:16:59 UTC (rev 996)
@@ -373,23 +373,6 @@
 		};
 /* End PBXBuildRule section */
 
-/* Begin PBXBuildStyle section */
-		B57131160AC81ECA000A6C36 /* Development */ = {
-			isa = PBXBuildStyle;
-			buildSettings = {
-				COPY_PHASE_STRIP = NO;
-			};
-			name = Development;
-		};
-		B57131170AC81ECA000A6C36 /* Deployment */ = {
-			isa = PBXBuildStyle;
-			buildSettings = {
-				COPY_PHASE_STRIP = YES;
-			};
-			name = Deployment;
-		};
-/* End PBXBuildStyle section */
-
 /* Begin PBXCopyFilesBuildPhase section */
 		700E2B6D085DE50C00CF158A /* CopyFiles */ = {
 			isa = PBXCopyFilesBuildPhase;
@@ -1776,12 +1759,6 @@
 		DCC30C4D0762532C008F7A48 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 702442D70859E0B00059BD9B /* Build configuration list for PBXProject "Avida" */;
-			buildSettings = {
-			};
-			buildStyles = (
-				B57131160AC81ECA000A6C36 /* Development */,
-				B57131170AC81ECA000A6C36 /* Deployment */,
-			);
 			hasScannedForEncodings = 0;
 			mainGroup = DCC30C490762532C008F7A48;
 			productRefGroup = DCC3164E07626CF3008F7A48 /* Products */;

Modified: branches/coopcomm/source/main/cOrganism.cc
===================================================================
--- branches/coopcomm/source/main/cOrganism.cc	2006-09-26 17:09:33 UTC (rev 995)
+++ branches/coopcomm/source/main/cOrganism.cc	2006-09-26 18:16:59 UTC (rev 996)
@@ -509,6 +509,33 @@
 /*! Attempt to send the message (which is actually based on the facing of the
 cell), and if successful, store the sent message, and check to see if sending this
 message completed any tasks.
+
+On Sep 26, 2006, at 1:57 PM, Ben Beckmann wrote:
+
+I noticed that the cStats::SentMessage function has a note that says "the sender and receiver fields of the message are not valid after this method completes".  This presents a problem.  Tasks that rely on the sender and/or receiver fields are no longer possible.  I looked through the code and didn't see any modifications of these fields, but that probably means I missed something.  Can cStats::SentMessage be rewritten so that the sender and receiver fields are not modified?
+
+Ben
+
+Hrm, probably put that note in the wrong place -- feel free to move it.
+
+The gist of the problem is this: When a message is sent, at the cpu-level we know the data and label fields, and we have a pointer to the sending organism.  These three values are set on the cOrgMessage instance.  The message gets passed to cOrganism::SendMessage, and thence to cPopulationCell::SendMessage.  At this point, we determine the identity of the receiving organism, and add the pointer to the receiving organism to the message.
+
+If the sending was successful, meaning that we could find a receiver, we hand the message off to cStats::SentMessage to update any needed statistics.  The message is still good in cOrganism::SendMessage on the return from cStats::SentMessage (in contrast to the note you mentioned?).  We then need to check for task completion, so we set the message field in the cTaskContext to the message that we just sent, and run the normal Avida task-checking process.
+
+Ok, so if a message-specific task is needed, the thing to do is check for the message field of the task context, and then do whatever checking you need to do.  While in cTaskLib::Task_*, the pointers to the sending and receiving organisms are VALID.  For example, see cTaskLib::Task_MaxID.
+
+The reason that note is there is that as soon as the cOrganism::SendMessage function completes, we can no longer rely upon the validity of the pointer to the receiving organism -- Specifically, it may point to a dead organism (one whose destructor has been called).  Why this is important is that the sending organism maintains two lists of sent messages -- but the receiver fields of these messages MUST NOT be used.  The sender's still good, provided that cOrganism owns the cOrgMessage instances (no references to sent messages outside of the sending organism).
+
+Actually, we should probably set the pointer to the receiving organism to NULL at the end of cOrganism::SendMessage (done & checked in).
+
+Also, I've added this email to the comments for cOrganism::SendMessage, just for good measure.  And have updated the note in cStats::SentMessage.
+
+In summary - You can use the sender and receiver pointers in cStat::SentMessage, and you can use them in cTaskLib::* provided that you don't use the pointer to receiving organisms in old messages.
+
+
+Cheers,
+-Dave
+
 */
 bool cOrganism::SendMessage(cAvidaContext& ctx, cOrgMessage& msg)
 {
@@ -570,8 +597,10 @@
       const int cur_inst = insts_triggered[i];
       m_hardware->ProcessBonusInst(ctx, cInstruction(cur_inst) );
     }
-    
-    // RunCallbacks();
+
+    // See comments above.
+    m_sent_messages.back()->SetReceiver(NULL);
+    m_sorted_sent_messages[msg.GetData()].SetReceiver(NULL);
     return true;
   } else {
     return false;

Modified: branches/coopcomm/source/main/cStats.cc
===================================================================
--- branches/coopcomm/source/main/cStats.cc	2006-09-26 17:09:33 UTC (rev 995)
+++ branches/coopcomm/source/main/cStats.cc	2006-09-26 18:16:59 UTC (rev 996)
@@ -886,8 +886,8 @@
 
 /*! This captures all information that can be gleaned from a single message.
 
-Note that the sender and receiver fields of the message are not valid after this
-method completes!
+IMPORTANT: Go look at the comments here before you rely too heavily cOrgMessages:
+\see cOrganism::SendMessage
 */
 void cStats::SentMessage(cOrgMessage& msg)
 {




More information about the Avida-cvs mailing list