[Avida-cvs] [avida-svn] r617 - in development: Avida.xcodeproj source/cpu source/main support/config

brysonda@myxo.css.msu.edu brysonda at myxo.css.msu.edu
Mon Apr 17 07:13:25 PDT 2006


Author: brysonda
Date: 2006-04-17 10:13:25 -0400 (Mon, 17 Apr 2006)
New Revision: 617

Removed:
   development/source/cpu/cHardwareSMT_Thread.cc
   development/source/cpu/cHardwareSMT_Thread.h
   development/source/cpu/nHardwareSMT.h
Modified:
   development/Avida.xcodeproj/project.pbxproj
   development/source/cpu/cHardware4Stack.cc
   development/source/cpu/cHardware4Stack.h
   development/source/cpu/cHardwareBase.h
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
   development/source/cpu/cHardwareSMT.cc
   development/source/cpu/cHardwareSMT.h
   development/source/main/cPopulation.cc
   development/support/config/inst_set.smt
   development/support/config/organism.smt
   development/support/config/organism.smtx
Log:
Rework Hardware threading methods.  Implement labeled SMT threads, similar to memory spaces.  Integrate SMT thread objects, remove external namespace constants.  Adjust SMT instruction set file to list new instructions.  Adjust SMT default organism to be 100 in length.

Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj	2006-04-14 18:17:00 UTC (rev 616)
+++ development/Avida.xcodeproj/project.pbxproj	2006-04-17 14:13:25 UTC (rev 617)
@@ -99,6 +99,7 @@
 		707AF0B209EAC7FD001AEA89 /* LandscapeActions.cc in Sources */ = {isa = PBXBuildFile; fileRef = 707AF04509EAB529001AEA89 /* LandscapeActions.cc */; };
 		707AF0B309EAC801001AEA89 /* LandscapeActions.cc in Sources */ = {isa = PBXBuildFile; fileRef = 707AF04509EAB529001AEA89 /* LandscapeActions.cc */; };
 		707AF0B409EAC805001AEA89 /* LandscapeActions.cc in Sources */ = {isa = PBXBuildFile; fileRef = 707AF04509EAB529001AEA89 /* LandscapeActions.cc */; };
+		709A09D409F3D3B400F9A4BF /* organism.smtx in CopyFiles */ = {isa = PBXBuildFile; fileRef = 707AF2F909EE8501001AEA89 /* organism.smtx */; };
 		70AA941A09D486CA006A24C8 /* system-alloc.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCF50209CFB0B400924128 /* system-alloc.cc */; };
 		70AA941B09D486CB006A24C8 /* tcmalloc-logging.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCF57F09CFBD3D00924128 /* tcmalloc-logging.cc */; };
 		70AA941C09D486CD006A24C8 /* tcmalloc.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCF56309CFBB9500924128 /* tcmalloc.cc */; };
@@ -212,14 +213,12 @@
 		70C1EFAD08C39F2100F50912 /* cHardwareBase.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1EFA308C39F2100F50912 /* cHardwareBase.cc */; };
 		70C1EFAE08C39F2100F50912 /* cHardwareCPU_Thread.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1EFA408C39F2100F50912 /* cHardwareCPU_Thread.cc */; };
 		70C1EFAF08C39F2100F50912 /* cHardwareCPU.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1EFA508C39F2100F50912 /* cHardwareCPU.cc */; };
-		70C1F02A08C3C71300F50912 /* cHardwareSMT_Thread.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F02208C3C71300F50912 /* cHardwareSMT_Thread.cc */; };
 		70C1F02B08C3C71300F50912 /* cHardwareSMT.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F02308C3C71300F50912 /* cHardwareSMT.cc */; };
 		70C1F02C08C3C71300F50912 /* cHardwareStatusPrinter.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F02408C3C71300F50912 /* cHardwareStatusPrinter.cc */; };
 		70C1F02E08C3C71300F50912 /* cHeadCPU.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F02608C3C71300F50912 /* cHeadCPU.cc */; };
 		70C1F02F08C3C71300F50912 /* cHeadMultiMem.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F02708C3C71300F50912 /* cHeadMultiMem.cc */; };
 		70C1F03008C3C71300F50912 /* cTestCPU.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F02808C3C71300F50912 /* cTestCPU.cc */; };
 		70C1F03108C3C71300F50912 /* cTestUtil.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F02908C3C71300F50912 /* cTestUtil.cc */; };
-		70C1F03208C3C71300F50912 /* cHardwareSMT_Thread.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F02208C3C71300F50912 /* cHardwareSMT_Thread.cc */; };
 		70C1F03308C3C71300F50912 /* cHardwareSMT.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F02308C3C71300F50912 /* cHardwareSMT.cc */; };
 		70C1F03408C3C71300F50912 /* cHardwareStatusPrinter.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F02408C3C71300F50912 /* cHardwareStatusPrinter.cc */; };
 		70C1F03608C3C71300F50912 /* cHeadCPU.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F02608C3C71300F50912 /* cHeadCPU.cc */; };
@@ -277,7 +276,6 @@
 		70DCACAA097AF7CC002F8733 /* cHardwareBase.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1EFA308C39F2100F50912 /* cHardwareBase.cc */; };
 		70DCACAB097AF7CC002F8733 /* cHardwareCPU_Thread.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1EFA408C39F2100F50912 /* cHardwareCPU_Thread.cc */; };
 		70DCACAC097AF7CC002F8733 /* cHardwareCPU.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1EFA508C39F2100F50912 /* cHardwareCPU.cc */; };
-		70DCACAD097AF7CC002F8733 /* cHardwareSMT_Thread.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F02208C3C71300F50912 /* cHardwareSMT_Thread.cc */; };
 		70DCACAE097AF7CC002F8733 /* cHardwareSMT.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F02308C3C71300F50912 /* cHardwareSMT.cc */; };
 		70DCACAF097AF7CC002F8733 /* cHardwareStatusPrinter.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F02408C3C71300F50912 /* cHardwareStatusPrinter.cc */; };
 		70DCACB0097AF7CC002F8733 /* cHeadCPU.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F02608C3C71300F50912 /* cHeadCPU.cc */; };
@@ -466,6 +464,7 @@
 				7039885409F00D150052ACE7 /* organism.default in CopyFiles */,
 				7039885509F00D190052ACE7 /* organism.sex in CopyFiles */,
 				7039885609F00D1A0052ACE7 /* organism.smt in CopyFiles */,
+				709A09D409F3D3B400F9A4BF /* organism.smtx in CopyFiles */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -785,7 +784,6 @@
 		70C1EFA308C39F2100F50912 /* cHardwareBase.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cHardwareBase.cc; sourceTree = "<group>"; };
 		70C1EFA408C39F2100F50912 /* cHardwareCPU_Thread.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cHardwareCPU_Thread.cc; sourceTree = "<group>"; };
 		70C1EFA508C39F2100F50912 /* cHardwareCPU.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cHardwareCPU.cc; sourceTree = "<group>"; };
-		70C1F01308C3C6FC00F50912 /* cHardwareSMT_Thread.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cHardwareSMT_Thread.h; sourceTree = "<group>"; };
 		70C1F01408C3C6FC00F50912 /* cHardwareSMT.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cHardwareSMT.h; sourceTree = "<group>"; };
 		70C1F01508C3C6FC00F50912 /* cHardwareStatusPrinter.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cHardwareStatusPrinter.h; sourceTree = "<group>"; };
 		70C1F01608C3C6FC00F50912 /* cHardwareTracer_4Stack.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cHardwareTracer_4Stack.h; sourceTree = "<group>"; };
@@ -797,8 +795,6 @@
 		70C1F01D08C3C6FC00F50912 /* cInstLibCPU.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cInstLibCPU.h; sourceTree = "<group>"; };
 		70C1F01F08C3C6FC00F50912 /* cTestCPU.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cTestCPU.h; sourceTree = "<group>"; };
 		70C1F02008C3C6FC00F50912 /* cTestUtil.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cTestUtil.h; sourceTree = "<group>"; };
-		70C1F02108C3C6FC00F50912 /* nHardwareSMT.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = nHardwareSMT.h; sourceTree = "<group>"; };
-		70C1F02208C3C71300F50912 /* cHardwareSMT_Thread.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cHardwareSMT_Thread.cc; sourceTree = "<group>"; };
 		70C1F02308C3C71300F50912 /* cHardwareSMT.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cHardwareSMT.cc; sourceTree = "<group>"; };
 		70C1F02408C3C71300F50912 /* cHardwareStatusPrinter.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cHardwareStatusPrinter.cc; sourceTree = "<group>"; };
 		70C1F02608C3C71300F50912 /* cHeadCPU.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cHeadCPU.cc; sourceTree = "<group>"; };
@@ -1324,8 +1320,6 @@
 				70C1EF9F08C39F0E00F50912 /* cHardwareCPU_Thread.h */,
 				70C5BD690905CE5F0028A785 /* cHardwareManager.cc */,
 				70C5BD6A0905CE5F0028A785 /* cHardwareManager.h */,
-				70C1F02208C3C71300F50912 /* cHardwareSMT_Thread.cc */,
-				70C1F01308C3C6FC00F50912 /* cHardwareSMT_Thread.h */,
 				70C1F02308C3C71300F50912 /* cHardwareSMT.cc */,
 				70C1F01408C3C6FC00F50912 /* cHardwareSMT.h */,
 				70C1F02408C3C71300F50912 /* cHardwareStatusPrinter.cc */,
@@ -1349,7 +1343,6 @@
 				70C1F0A808C3FF1800F50912 /* nHardware.h */,
 				70C1F06108C3CDEA00F50912 /* nHardware4Stack.h */,
 				70C1F0FC08C40B1B00F50912 /* nHardwareCPU.h */,
-				70C1F02108C3C6FC00F50912 /* nHardwareSMT.h */,
 				70C1EF6708C395D300F50912 /* sCPUStats.h */,
 				706D30CC0852328F00D7DC8F /* tInstLib.h */,
 				DCC30FA90762539D008F7A48 /* CMakeLists.txt */,
@@ -1937,7 +1930,6 @@
 				70C1EFAD08C39F2100F50912 /* cHardwareBase.cc in Sources */,
 				70C1EFAE08C39F2100F50912 /* cHardwareCPU_Thread.cc in Sources */,
 				70C1EFAF08C39F2100F50912 /* cHardwareCPU.cc in Sources */,
-				70C1F03208C3C71300F50912 /* cHardwareSMT_Thread.cc in Sources */,
 				70C1F03308C3C71300F50912 /* cHardwareSMT.cc in Sources */,
 				70C1F03408C3C71300F50912 /* cHardwareStatusPrinter.cc in Sources */,
 				70C1F03608C3C71300F50912 /* cHeadCPU.cc in Sources */,
@@ -2074,7 +2066,6 @@
 				70DCACAA097AF7CC002F8733 /* cHardwareBase.cc in Sources */,
 				70DCACAB097AF7CC002F8733 /* cHardwareCPU_Thread.cc in Sources */,
 				70DCACAC097AF7CC002F8733 /* cHardwareCPU.cc in Sources */,
-				70DCACAD097AF7CC002F8733 /* cHardwareSMT_Thread.cc in Sources */,
 				70DCACAE097AF7CC002F8733 /* cHardwareSMT.cc in Sources */,
 				70DCACAF097AF7CC002F8733 /* cHardwareStatusPrinter.cc in Sources */,
 				70DCACB0097AF7CC002F8733 /* cHeadCPU.cc in Sources */,
@@ -2193,7 +2184,6 @@
 				70C1EFA808C39F2100F50912 /* cHardwareBase.cc in Sources */,
 				70C1EFA908C39F2100F50912 /* cHardwareCPU_Thread.cc in Sources */,
 				70C1EFAA08C39F2100F50912 /* cHardwareCPU.cc in Sources */,
-				70C1F02A08C3C71300F50912 /* cHardwareSMT_Thread.cc in Sources */,
 				70C1F02B08C3C71300F50912 /* cHardwareSMT.cc in Sources */,
 				70C1F02C08C3C71300F50912 /* cHardwareStatusPrinter.cc in Sources */,
 				70C1F02E08C3C71300F50912 /* cHeadCPU.cc in Sources */,

Modified: development/source/cpu/cHardware4Stack.cc
===================================================================
--- development/source/cpu/cHardware4Stack.cc	2006-04-14 18:17:00 UTC (rev 616)
+++ development/source/cpu/cHardware4Stack.cc	2006-04-17 14:13:25 UTC (rev 617)
@@ -324,7 +324,7 @@
   
   for (int i = 0; i < num_inst_exec; i++) {
     // Setup the hardware for the next instruction to be executed.
-    NextThread();
+    ThreadNext();
     AdvanceIP() = true;
     IP().Adjust();
     
@@ -1034,7 +1034,7 @@
   
   // Note the current thread and set the current back one.
   const int kill_thread = cur_thread;
-  PrevThread();
+  ThreadPrev();
   
   // Turn off this bit in the thread_id_chart...
   thread_id_chart ^= 1 << threads[kill_thread].GetID();

Modified: development/source/cpu/cHardware4Stack.h
===================================================================
--- development/source/cpu/cHardware4Stack.h	2006-04-14 18:17:00 UTC (rev 616)
+++ development/source/cpu/cHardware4Stack.h	2006-04-17 14:13:25 UTC (rev 617)
@@ -125,7 +125,12 @@
   const cCodeLabel & GetReadLabel() const { return threads[cur_thread].read_label; }
   cCodeLabel & GetReadLabel() { return threads[cur_thread].read_label; }
   
-
+  
+  // ---------- Thread Manipulation -----------
+  bool ForkThread(); // Adds a new thread based off of m_cur_thread.
+  bool KillThread(); // Kill the current thread!
+  
+  
   // ---------- Instruction Helpers -----------
   int FindModifiedStack(int default_stack);
   int FindModifiedHead(int default_head);
@@ -206,30 +211,24 @@
 
   
   // --------  Thread Manipulation  --------
-  bool ForkThread(); // Adds a new thread based off of cur_thread.
-  bool KillThread(); // Kill the current thread!
-  inline void PrevThread(); // Shift the current thread in use.
-  inline void NextThread();
-  inline void SetThread(int value);
-  cInjectGenotype* GetCurThreadOwner() { return threads[cur_thread].owner; }
-  cInjectGenotype* GetThreadOwner(int in_thread) { return threads[in_thread].owner; }
-  void SetThreadOwner(cInjectGenotype* in_genotype) { threads[cur_thread].owner = in_genotype; }
+  bool ThreadSelect(const int thread_num);
+  bool ThreadSelect(const cCodeLabel& in_label) { return false; } // Labeled threads not supported
+  inline void ThreadPrev(); // Shift the current thread in use.
+  inline void ThreadNext();
+  cInjectGenotype* ThreadGetOwner() { return threads[cur_thread].owner; }
+  void ThreadSetOwner(cInjectGenotype* in_genotype) { threads[cur_thread].owner = in_genotype; }
 	
+  int GetNumThreads() const     { return threads.GetSize(); }
+  int GetCurThread() const      { return cur_thread; }
+  int GetCurThreadID() const    { return threads[cur_thread].GetID(); }
+
   
   // --------  Parasite Stuff  --------
   int TestParasite() const;
   bool InjectHost(const cCodeLabel& in_label, const cGenome& injection);
-  bool InjectThread(const cCodeLabel& in_label) { return false; }
+  bool InjectThread(const cCodeLabel& in_label, const cGenome& injection) { return false; }
 
   
-  // --------  Accessors  --------
-  int GetNumThreads() const     { return threads.GetSize(); }
-  int GetCurThread() const      { return cur_thread; }
-  int GetCurThreadID() const    { return threads[cur_thread].GetID(); }
-  int GetThreadDist() const {
-    if (GetNumThreads() == 1) return 0;
-    return threads[0].heads[nHardware::HEAD_IP].GetPosition() - threads[1].heads[nHardware::HEAD_IP].GetPosition();
-  }
 	
   
 private:
@@ -270,24 +269,28 @@
 };
 
 
-inline void cHardware4Stack::NextThread()
+inline bool cHardware4Stack::ThreadSelect(const int thread_num)
 {
+  if (thread_num >= 0 && thread_num < threads.GetSize()) {
+    cur_thread = thread_num;
+    return true;
+  }
+  
+  return false;
+}
+
+inline void cHardware4Stack::ThreadNext()
+{
   cur_thread++;
   if (cur_thread >= GetNumThreads()) cur_thread = 0;
 }
 
-inline void cHardware4Stack::PrevThread()
+inline void cHardware4Stack::ThreadPrev()
 {
   if (cur_thread == 0) cur_thread = GetNumThreads() - 1;
   else cur_thread--;
 }
 
-inline void cHardware4Stack::SetThread(int value)
-{
-  if (value>=0 && value < GetNumThreads())
-    cur_thread=value;
-}
-
 inline int cHardware4Stack::GetStack(int depth, int stack_id, int in_thread) const
 {
   if(stack_id<0 || stack_id>nHardware4Stack::NUM_STACKS) stack_id=0;

Modified: development/source/cpu/cHardwareBase.h
===================================================================
--- development/source/cpu/cHardwareBase.h	2006-04-14 18:17:00 UTC (rev 616)
+++ development/source/cpu/cHardwareBase.h	2006-04-17 14:13:25 UTC (rev 617)
@@ -117,29 +117,23 @@
   
   
   // --------  Thread Manipulation  --------
-  virtual bool ForkThread() = 0;
-  virtual bool KillThread() = 0;
-  virtual void PrevThread() = 0;
-  virtual void NextThread() = 0;
-  virtual void SetThread(int value) = 0;
-  virtual cInjectGenotype* GetCurThreadOwner() = 0;
-  virtual cInjectGenotype* GetThreadOwner(int in_thread) = 0;
-  virtual void SetThreadOwner(cInjectGenotype* in_genotype) = 0;
+  virtual bool ThreadSelect(const int thread_id) = 0;
+  virtual bool ThreadSelect(const cCodeLabel& in_label) = 0;
+  virtual void ThreadPrev() = 0;
+  virtual void ThreadNext() = 0;
+  virtual cInjectGenotype* ThreadGetOwner() = 0;
+  virtual void ThreadSetOwner(cInjectGenotype* in_genotype) = 0;
+
+  virtual int GetNumThreads() const = 0;
+  virtual int GetCurThread() const = 0;
+  virtual int GetCurThreadID() const = 0;
   
   
   // --------  Parasite Stuff  --------
   virtual int TestParasite() const = 0;
   virtual bool InjectHost(const cCodeLabel& in_label, const cGenome& injection) = 0;
-  virtual bool InjectThread(const cCodeLabel& in_label) = 0;
   
-  
-  // --------  Accessors  --------
-  virtual int GetNumThreads() const = 0;
-  virtual int GetCurThread() const = 0;
-  virtual int GetCurThreadID() const = 0;
-  virtual int GetThreadDist() const = 0;
-  
-  
+    
   // --------  Mutation  --------
   virtual int PointMutate(cAvidaContext& ctx, const double mut_rate);
   virtual bool TriggerMutations(cAvidaContext& ctx, int trigger);

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2006-04-14 18:17:00 UTC (rev 616)
+++ development/source/cpu/cHardwareCPU.cc	2006-04-17 14:13:25 UTC (rev 617)
@@ -453,7 +453,7 @@
   
   for (int i = 0; i < num_inst_exec; i++) {
     // Setup the hardware for the next instruction to be executed.
-    NextThread();
+    ThreadNext();
     advance_ip = true;
     IP().Adjust();
     
@@ -965,19 +965,6 @@
   return true; // (inject succeeds!)
 }
 
-bool cHardwareCPU::InjectThread(const cCodeLabel& in_label)
-{
-  // Make sure the genome will be below max size after injection.
-  
-  if(ForkThread())
-  {
-    organism->GetPhenotype().IsMultiThread() = true;
-    return true;
-  }
-
-  return false;
-}
-
 void cHardwareCPU::InjectCode(const cGenome & inject_code, const int line_num)
 {
   assert(line_num >= 0);
@@ -1084,7 +1071,7 @@
   
   // Note the current thread and set the current back one.
   const int kill_thread = cur_thread;
-  PrevThread();
+  ThreadPrev();
   
   // Turn off this bit in the thread_id_chart...
   thread_id_chart ^= 1 << threads[kill_thread].GetID();
@@ -2228,7 +2215,7 @@
   GetLabel().Rotate(1, nHardwareCPU::NUM_NOPS);
   
   if (host_organism->GetHardware().InjectHost(GetLabel(), inject_code)) {
-    host_organism->GetHardware().InjectThread(GetLabel());
+    if (ForkThread()) organism->GetPhenotype().IsMultiThread() = true;
   }
   
   // Set the relevent flags.

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2006-04-14 18:17:00 UTC (rev 616)
+++ development/source/cpu/cHardwareCPU.h	2006-04-17 14:13:25 UTC (rev 617)
@@ -120,7 +120,11 @@
   cCodeLabel& GetReadLabel() { return threads[cur_thread].read_label; }
   
   
+  // --------  Thread Manipulation  -------
+  bool ForkThread(); // Adds a new thread based off of cur_thread.
+  bool KillThread(); // Kill the current thread!
   
+  
   // ---------- Instruction Helpers -----------
   int FindModifiedRegister(int default_register);
   int FindModifiedHead(int default_head);
@@ -197,32 +201,23 @@
 
   
   // --------  Thread Manipulation  --------
-  bool ForkThread(); // Adds a new thread based off of cur_thread.
-  bool KillThread(); // Kill the current thread!
-  inline void PrevThread(); // Shift the current thread in use.
-  inline void NextThread();
-  inline void SetThread(int value);
-  cInjectGenotype* GetCurThreadOwner() { return NULL; } // @DMB - cHardwareCPU does not really implement cInjectGenotype yet
-  cInjectGenotype* GetThreadOwner(int in_thread) { return NULL; }
-  void SetThreadOwner(cInjectGenotype* in_genotype) { return; }
+  bool ThreadSelect(const int thread_num);
+  bool ThreadSelect(const cCodeLabel& in_label) { return false; } // Labeled threads not supported
+  inline void ThreadPrev(); // Shift the current thread in use.
+  inline void ThreadNext();
+  cInjectGenotype* ThreadGetOwner() { return NULL; } // @DMB - cHardwareCPU does not really implement cInjectGenotype yet
+  void ThreadSetOwner(cInjectGenotype* in_genotype) { return; }
   
+  int GetNumThreads() const     { return threads.GetSize(); }
+  int GetCurThread() const      { return cur_thread; }
+  int GetCurThreadID() const    { return threads[cur_thread].GetID(); }
   
+  
   // --------  Parasite Stuff  --------
   int TestParasite() const;
   bool InjectHost(const cCodeLabel& in_label, const cGenome& injection);
-  bool InjectThread(const cCodeLabel& in_label);
 
   
-  // --------  Accessors  --------
-  int GetNumThreads() const     { return threads.GetSize(); }
-  int GetCurThread() const      { return cur_thread; }
-  int GetCurThreadID() const    { return threads[cur_thread].GetID(); }
-  int GetThreadDist() const {
-    if (GetNumThreads() == 1) return 0;
-    return threads[0].heads[nHardware::HEAD_IP].GetPosition() - threads[1].heads[nHardware::HEAD_IP].GetPosition();
-  }
-
-
   // Non-Standard Methods
   
   int GetActiveStack() const { return threads[cur_thread].cur_stack; }
@@ -432,24 +427,28 @@
 };
 
 
-inline void cHardwareCPU::NextThread()
+inline bool cHardwareCPU::ThreadSelect(const int thread_num)
 {
+  if (thread_num >= 0 && thread_num < threads.GetSize()) {
+    cur_thread = thread_num;
+    return true;
+  }
+  
+  return false;
+}
+
+inline void cHardwareCPU::ThreadNext()
+{
   cur_thread++;
   if (cur_thread >= GetNumThreads()) cur_thread = 0;
 }
 
-inline void cHardwareCPU::PrevThread()
+inline void cHardwareCPU::ThreadPrev()
 {
   if (cur_thread == 0) cur_thread = GetNumThreads() - 1;
   else cur_thread--;
 }
 
-inline void cHardwareCPU::SetThread(int value)
-{
-     if (value>=0 && value < GetNumThreads())
-          cur_thread=value;
-}
-
 inline void cHardwareCPU::StackPush(int value)
 {
   if (threads[cur_thread].cur_stack == 0) {

Modified: development/source/cpu/cHardwareSMT.cc
===================================================================
--- development/source/cpu/cHardwareSMT.cc	2006-04-14 18:17:00 UTC (rev 616)
+++ development/source/cpu/cHardwareSMT.cc	2006-04-17 14:13:25 UTC (rev 617)
@@ -11,26 +11,23 @@
 
 #include "cAvidaContext.h"
 #include "cCPUTestInfo.h"
-#include "functions.h"
-#include "cGenomeUtil.h"
 #include "cInstLibBase.h"
 #include "cInstSet.h"
-#include "cHardwareManager.h"
 #include "cHardwareTracer.h"
 #include "cHardwareTracer_SMT.h"
 #include "cMutation.h"
 #include "cMutationLib.h"
-#include "nMutation.h"
 #include "cOrganism.h"
 #include "cPhenotype.h"
 #include "cRandom.h"
-#include "cStringUtil.h"
 #include "cTestCPU.h"
-#include "cWorldDriver.h"
 #include "cWorld.h"
 
-#include <limits.h>
+#include "functions.h"
+#include "nMutation.h"
 
+#include <iomanip>
+
 using namespace std;
 
 tInstLib<cHardwareSMT::tMethod>* cHardwareSMT::s_inst_slib = cHardwareSMT::initInstLib();
@@ -43,10 +40,10 @@
     int nop_mod;
   };
   static const cNOPEntry s_n_array[] = {
-    cNOPEntry("Nop-A", nHardwareSMT::STACK_AX),
-    cNOPEntry("Nop-B", nHardwareSMT::STACK_BX),
-    cNOPEntry("Nop-C", nHardwareSMT::STACK_CX),
-    cNOPEntry("Nop-D", nHardwareSMT::STACK_DX),
+    cNOPEntry("Nop-A", STACK_AX),
+    cNOPEntry("Nop-B", STACK_BX),
+    cNOPEntry("Nop-C", STACK_CX),
+    cNOPEntry("Nop-D", STACK_DX),
   };
 	
   struct cInstEntry {
@@ -87,15 +84,16 @@
     cInstEntry("Push-Comp", &cHardwareSMT::Inst_PushComplement), // 30
     cInstEntry("Val-Delete", &cHardwareSMT::Inst_ValDelete), // 31
     cInstEntry("Val-Copy", &cHardwareSMT::Inst_ValCopy), // 32
-    cInstEntry("Thread-Create", &cHardwareSMT::Inst_ThreadCreate), // 33
-    cInstEntry("Thread-Exit", &cHardwareSMT::Inst_ThreadExit), // 34
-    cInstEntry("IO", &cHardwareSMT::Inst_IO), // 35
-    cInstEntry("Inject", &cHardwareSMT::Inst_Inject), // 36
-    cInstEntry("Apoptosis", &cHardwareSMT::Inst_Apoptosis), // 37
-    cInstEntry("Net-Get", &cHardwareSMT::Inst_NetGet), // 38
-    cInstEntry("Net-Send", &cHardwareSMT::Inst_NetSend), // 39
-    cInstEntry("Net-Receive", &cHardwareSMT::Inst_NetReceive), // 40
-    cInstEntry("Net-Last", &cHardwareSMT::Inst_NetLast) // 41
+    cInstEntry("IO", &cHardwareSMT::Inst_IO), // 33
+    cInstEntry("Thread-Create", &cHardwareSMT::Inst_ThreadCreate), // 34
+    cInstEntry("Thread-Cancel", &cHardwareSMT::Inst_ThreadCancel), // 35
+    cInstEntry("Thread-Kill", &cHardwareSMT::Inst_ThreadKill), // 36
+    cInstEntry("Inject", &cHardwareSMT::Inst_Inject), // 37
+    cInstEntry("Apoptosis", &cHardwareSMT::Inst_Apoptosis), // 38
+    cInstEntry("Net-Get", &cHardwareSMT::Inst_NetGet), // 39
+    cInstEntry("Net-Send", &cHardwareSMT::Inst_NetSend), // 40
+    cInstEntry("Net-Receive", &cHardwareSMT::Inst_NetReceive), // 41
+    cInstEntry("Net-Last", &cHardwareSMT::Inst_NetLast) // 42
   };
 	
   const int n_size = sizeof(s_n_array)/sizeof(cNOPEntry);
@@ -125,8 +123,9 @@
 }
 
 cHardwareSMT::cHardwareSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
-: cHardwareBase(world, in_organism, in_m_inst_set), m_mem_array(1),
-m_mem_lbls(Pow(nHardwareSMT::NUM_NOPS, nHardwareSMT::MAX_MEMSPACE_LABEL) / nHardwareSMT::MEM_LBLS_HASH_FACTOR)
+: cHardwareBase(world, in_organism, in_m_inst_set), m_mem_array(1)
+, m_mem_lbls(Pow(NUM_NOPS, MAX_MEMSPACE_LABEL) / MEM_LBLS_HASH_FACTOR)
+, m_thread_lbls(Pow(NUM_NOPS, MAX_THREAD_LABEL) / THREAD_LBLS_HASH_FACTOR)
 {
   m_functions = s_inst_slib->GetFunctions();
 	
@@ -147,11 +146,10 @@
 	
   // Reset that single thread.
   m_threads[0].Reset(this, 0);
-  thread_id_chart = 1; // Mark only the first thread as taken...
   m_cur_thread = 0;
 		
   // Reset all stacks (local and global)
-  for(int i = 0; i < nHardwareSMT::NUM_STACKS; i++) {
+  for(int i = 0; i < NUM_STACKS; i++) {
 		Stack(i).Clear();
 	}
 	
@@ -170,40 +168,53 @@
   organism->NetReset();
 }
 
+void cHardwareSMT::cLocalThread::Reset(cHardwareBase* in_hardware, int mem_space)
+{
+  for (int i = 0; i < NUM_LOCAL_STACKS; i++) local_stacks[i].Clear();
+  for (int i = 0; i < nHardware::NUM_HEADS; i++) heads[i].Reset(mem_space, in_hardware);
+	
+  cur_head = nHardware::HEAD_IP;
+  read_label.Clear();
+  next_label.Clear();
+  running = true;
+  owner = NULL;  
+}
+
+
+
 // This function processes the very next command in the genome, and is made
 // to be as optimized as possible.  This is the heart of avida.
-
 void cHardwareSMT::SingleProcess(cAvidaContext& ctx)
 {
   // Mark this organism as running...
   organism->SetRunning(true);
 	
-  cPhenotype & phenotype = organism->GetPhenotype();
+  cPhenotype& phenotype = organism->GetPhenotype();
   phenotype.IncTimeUsed();
 	
   const int num_inst_exec = (m_world->GetConfig().THREAD_SLICING_METHOD.Get() == 1) ? GetNumThreads() : 1;
   
   for (int i = 0; i < num_inst_exec; i++) {
     // Setup the hardware for the next instruction to be executed.
-    NextThread();
+    ThreadNext();
+    if (!ThreadIsRunning()) continue;
+    
     AdvanceIP() = true;
     IP().Adjust();
 		
 #ifdef BREAKPOINTS
-    if (IP().FlagBreakpoint()) {
-      organism->DoBreakpoint();
-    }
+    if (IP().FlagBreakpoint()) organism->DoBreakpoint();
 #endif
     
     // Print the status of this CPU at each step...
-    if (m_tracer != NULL) {
-      if (cHardwareTracer_SMT* tracer = dynamic_cast<cHardwareTracer_SMT *>(m_tracer)) {
-        tracer->TraceHardware_SMT(*this);
-      }
+    if (m_tracer)
+    {
+      cHardwareTracer_SMT* tracer = dynamic_cast<cHardwareTracer_SMT *>(m_tracer);
+      if (tracer) tracer->TraceHardware_SMT(*this);
     }
     
     // Find the instruction to be executed
-    const cInstruction & cur_inst = IP().GetInst();
+    const cInstruction& cur_inst = IP().GetInst();
 		
     // Test if costs have been paid and it is okay to execute this now...
     const bool exec = SingleProcess_PayCosts(ctx, cur_inst);
@@ -215,8 +226,8 @@
       // Some instruction (such as jump) may turn advance_ip off.  Ususally
       // we now want to move to the next instruction in the memory.
       if (AdvanceIP() == true) IP().Advance();
-    } // if exec
-  } // Previous was executed once for each thread...
+    }
+  }
   
   // Kill creatures who have reached their max num of instructions executed
   const int max_executed = organism->GetMaxExecuted();
@@ -228,6 +239,7 @@
   organism->SetRunning(false);
 }
 
+
 // This method will test to see if all costs have been paid associated
 // with executing an instruction and only return true when that instruction
 // should proceed.
@@ -323,7 +335,7 @@
   }
 	
   for (int i = 0; i < GetNumThreads(); i++) {
-    for(int j=0; j < nHardwareSMT::NUM_LOCAL_STACKS; j++)
+    for(int j=0; j < NUM_LOCAL_STACKS; j++)
 			if (m_threads[i].local_stacks[j].OK() == false) return false;
     if (m_threads[i].next_label.OK() == false) return false;
   }
@@ -336,17 +348,17 @@
   fp << organism->GetPhenotype().GetTimeUsed() << " "
 	<< "IP:(" << IP().GetMemSpace() << ", " << IP().GetPosition() << ")    "
 	
-	<< "AX:" << Stack(nHardwareSMT::STACK_AX).Top() << " "
-	<< setbase(16) << "[0x" << Stack(nHardwareSMT::STACK_AX).Top() << "]  " << setbase(10)
+	<< "AX:" << Stack(STACK_AX).Top() << " "
+	<< setbase(16) << "[0x" << Stack(STACK_AX).Top() << "]  " << setbase(10)
 	
-	<< "BX:" << Stack(nHardwareSMT::STACK_BX).Top() << " "
-	<< setbase(16) << "[0x" << Stack(nHardwareSMT::STACK_BX).Top() << "]  " << setbase(10)
+	<< "BX:" << Stack(STACK_BX).Top() << " "
+	<< setbase(16) << "[0x" << Stack(STACK_BX).Top() << "]  " << setbase(10)
 	
-	<< "CX:" << Stack(nHardwareSMT::STACK_CX).Top() << " "
-	<< setbase(16) << "[0x" << Stack(nHardwareSMT::STACK_CX).Top() << "]  " << setbase(10)
+	<< "CX:" << Stack(STACK_CX).Top() << " "
+	<< setbase(16) << "[0x" << Stack(STACK_CX).Top() << "]  " << setbase(10)
 	
-	<< "DX:" << Stack(nHardwareSMT::STACK_DX).Top() << " "
-	<< setbase(16) << "[0x" << Stack(nHardwareSMT::STACK_DX).Top() << "]  " << setbase(10)
+	<< "DX:" << Stack(STACK_DX).Top() << " "
+	<< setbase(16) << "[0x" << Stack(STACK_DX).Top() << "]  " << setbase(10)
 	
 	<< endl;
 	
@@ -368,18 +380,11 @@
 }
 
 
-bool cHardwareSMT::MemorySpaceExists(const cCodeLabel& label)
-{
-  int null;
-  if (label.GetSize() == 0 || m_mem_lbls.Find(label.AsInt(nHardwareSMT::NUM_NOPS), null)) return true;
-  return false;
-}
-
 int cHardwareSMT::FindMemorySpaceLabel(const cCodeLabel& label, int mem_space)
 {
 	if (label.GetSize() == 0) return 0;
   
-  int hash_key = label.AsInt(nHardwareSMT::NUM_NOPS);
+  int hash_key = label.AsInt(NUM_NOPS);
   if (!m_mem_lbls.Find(hash_key, mem_space)) {
     mem_space = m_mem_array.GetSize();
     m_mem_array.Resize(mem_space + 1);
@@ -721,7 +726,7 @@
   m_mem_array[mem_space_used] = cGenome("a"); 
 	
   for (int x = 0; x < nHardware::NUM_HEADS; x++) GetHead(x).Reset(IP().GetMemSpace(), this);
-  for (int x = 0; x < nHardwareSMT::NUM_LOCAL_STACKS; x++) Stack(x).Clear();
+  for (int x = 0; x < NUM_LOCAL_STACKS; x++) Stack(x).Clear();
   
   AdvanceIP() = false;
   
@@ -731,13 +736,16 @@
 //This is the code run by the TARGET of an injection.  This RECIEVES the infection.
 bool cHardwareSMT::InjectHost(const cCodeLabel& in_label, const cGenome& inject_code)
 {
-  // Inject fails if the memory space is already in use.
-  if (MemorySpaceExists(in_label)) return false;
+  // Inject fails if the memory space is already in use or thread exists
+  if (MemorySpaceExists(in_label) || FindThreadLabel(in_label) == -1) return false;
 
   // Otherwise create the memory space and copy in the genome
-  int mem_space_used = FindMemorySpaceLabel(GetLabel(), -1);
+  int mem_space_used = FindMemorySpaceLabel(in_label, -1);
   assert(mem_space_used == -1);
   m_mem_array[mem_space_used] = inject_code;
+  
+  // Create a thread for this parasite
+  if (!ThreadCreate(in_label, mem_space_used)) return false; // Partially failed injection, could not create thread
 
   return true;
 }
@@ -776,22 +784,44 @@
 }
 
 
-bool cHardwareSMT::ForkThread()
+int cHardwareSMT::ThreadCreate(const cCodeLabel& label, int mem_space)
 {
-  const int num_threads = GetNumThreads();
-  if (num_threads == m_world->GetConfig().MAX_CPU_THREADS.Get()) return false;
-	
-  // Make room for the new thread.
-  m_threads.Resize(num_threads + 1);
+  int thread_id = m_threads.GetSize();
   
-  // Find the first free bit in thread_id_chart to determine the new thread id.
-  int new_id = 0;
-  while ( (thread_id_chart >> new_id) & 1 == 1) new_id++;
-  thread_id_chart |= (1 << new_id);
-
+  // Check for thread cap, base thread label (i.e. no label)
+  if (thread_id == m_world->GetConfig().MAX_CPU_THREADS.Get() || label.GetSize() == 0) return -1;	
+  
+  // Check for existing thread
+  int hash_key = label.AsInt(NUM_NOPS);
+  if (m_thread_lbls.Find(hash_key, thread_id)) {
+    if (m_threads[thread_id].running) {
+      return -1;  // Thread exists, and is running... call fails
+    } else {
+      m_threads[thread_id].Reset(this, mem_space);
+      return thread_id;
+    }
+  }
+  
+  // Add new thread entry
+  m_threads.Resize(thread_id + 1);
+  m_thread_lbls.Add(hash_key, thread_id);
+    
   // Setup this thread into the current selected memory space (Flow Head)
-  m_threads[num_threads].Reset(this, new_id, GetHead(nHardware::HEAD_FLOW).GetMemSpace());
+  m_threads[thread_id].Reset(this, GetHead(nHardware::HEAD_FLOW).GetMemSpace());
 	
+  return thread_id;
+}
+
+bool cHardwareSMT::ThreadKill(const int thread_id)
+{
+  if (thread_id < 1 || thread_id >= m_threads.GetSize()) return false;
+
+  // Increment thread, if killing current thread
+  if (m_cur_thread == thread_id) ThreadNext();
+  
+  // Set this thread to not running
+  m_threads[thread_id].running = false;
+	
   return true;
 }
 
@@ -802,33 +832,14 @@
 }
 
 
-bool cHardwareSMT::KillThread()
-{
-  // Make sure that there is always at least one thread...
-  if (GetNumThreads() == 1) return false;
-	
-  // Note the current thread and set the current back one.
-  const int kill_thread = m_cur_thread;
-  PrevThread();
-  if (m_cur_thread > kill_thread) m_cur_thread--;
-  
-  // Turn off this bit in the thread_id_chart...
-  thread_id_chart ^= 1 << m_threads[kill_thread].GetID();
-	
-  // Kill the thread!
-  m_threads.Remove(kill_thread);	
-	
-  return true;
-}
 
-
 ////////////////////////////
 //  Instruction Helpers...
 ////////////////////////////
 
 inline int cHardwareSMT::FindModifiedStack(int default_stack)
 {
-  assert(default_stack < nHardwareSMT::NUM_STACKS);  // Stack ID too high.
+  assert(default_stack < NUM_STACKS);  // Stack ID too high.
 	
   if (m_inst_set->IsNop(IP().GetNextInst())) {
     IP().Advance();
@@ -840,7 +851,7 @@
 
 inline int cHardwareSMT::FindModifiedNextStack(int default_stack)
 {
-  assert(default_stack < nHardwareSMT::NUM_STACKS);  // Stack ID too high.
+  assert(default_stack < NUM_STACKS);  // Stack ID too high.
 	
   if (m_inst_set->IsNop(IP().GetNextInst())) {
     IP().Advance();
@@ -854,7 +865,7 @@
 
 inline int cHardwareSMT::FindModifiedPreviousStack(int default_stack)
 {
-  assert(default_stack < nHardwareSMT::NUM_STACKS);  // Stack ID too high.
+  assert(default_stack < NUM_STACKS);  // Stack ID too high.
 	
   if (m_inst_set->IsNop(IP().GetNextInst())) {
     IP().Advance();
@@ -868,7 +879,7 @@
 
 inline int cHardwareSMT::FindModifiedComplementStack(int default_stack)
 {
-  assert(default_stack < nHardwareSMT::NUM_STACKS);  // Stack ID too high.
+  assert(default_stack < NUM_STACKS);  // Stack ID too high.
 	
   if (m_inst_set->IsNop(IP().GetNextInst())) {
     IP().Advance();
@@ -895,17 +906,17 @@
 
 inline int cHardwareSMT::FindNextStack(int default_stack)
 {
-  return (default_stack + 1) % nHardwareSMT::NUM_STACKS;
+  return (default_stack + 1) % NUM_STACKS;
 }
 
 inline int cHardwareSMT::FindPreviousStack(int default_stack)
 {
-  return (default_stack + nHardwareSMT::NUM_STACKS - 1) % nHardwareSMT::NUM_STACKS;
+  return (default_stack + NUM_STACKS - 1) % NUM_STACKS;
 }
 
 inline int cHardwareSMT::FindComplementStack(int base_stack)
 {
-  return (base_stack + 2) % nHardwareSMT::NUM_STACKS;
+  return (base_stack + 2) % NUM_STACKS;
 }
 
 
@@ -1063,20 +1074,17 @@
 		}
 		else if (div_method == DIVIDE_METHOD_BIRTH)
 		{
-			if(!organism->GetPhenotype().IsModified() && GetNumThreads() > 1 || GetNumThreads() > 2) {
-        //if this isn't the only thread, get rid of it!
-        // *** this can cause a concurrency problem if we have multiprocessor support for single
-        // *** organisms...don't think that's happening anytime soon though @law
-	      KillThread();
+			if((!organism->GetPhenotype().IsModified() && GetNumThreads() > 1) || GetNumThreads() > 2) {
+	      ThreadKill(m_cur_thread);
 	    } else {
         //this will reset the current thread's heads and stacks.  It will 
-        //not touch any other m_threads or memory spaces (ie: parasites)
+        //not touch any other threads or memory spaces (ie: parasites)
 	      for(int x = 0; x < nHardware::NUM_HEADS; x++) {
 					GetHead(x).Reset(0, this);
 				}
-	      for(int x = 0; x < nHardwareSMT::NUM_LOCAL_STACKS; x++) {
+	      for(int x = 0; x < NUM_LOCAL_STACKS; x++) {
 					Stack(x).Clear();
-				}	  
+				}
 	    }
 		}
 		AdvanceIP() = false;
@@ -1086,10 +1094,13 @@
 }
 
 
+// --------  Begin Core Instruction Set --------
+
+
 //6
 bool cHardwareSMT::Inst_ShiftR(cAvidaContext& ctx)
 {
-  const int dst = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int dst = FindModifiedStack(STACK_BX);
 #ifdef SMT_FULLY_ASSOCIATIVE
   const int src = FindModifiedStack(dst);
 #else
@@ -1104,7 +1115,7 @@
 //7
 bool cHardwareSMT::Inst_ShiftL(cAvidaContext& ctx)
 {
-  const int dst = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int dst = FindModifiedStack(STACK_BX);
 #ifdef SMT_FULLY_ASSOCIATIVE
   const int src = FindModifiedStack(dst);
 #else
@@ -1119,13 +1130,13 @@
 //8
 bool cHardwareSMT::Inst_Val_Nand(cAvidaContext& ctx)
 {
-  const int dst = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int dst = FindModifiedStack(STACK_BX);
 #ifdef SMT_FULLY_ASSOCIATIVE
-  const int op1 = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int op1 = FindModifiedStack(STACK_BX);
   const int op2 = FindModifiedNextStack(op1);
 #else
-  const int op1 = nHardwareSMT::STACK_BX;
-  const int op2 = nHardwareSMT::STACK_CX;
+  const int op1 = STACK_BX;
+  const int op2 = STACK_CX;
 #endif
   Stack(dst).Push(~(Stack(op1).Top() & Stack(op2).Top()));
   return true;
@@ -1134,13 +1145,13 @@
 //9
 bool cHardwareSMT::Inst_Val_Add(cAvidaContext& ctx)
 {
-  const int dst = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int dst = FindModifiedStack(STACK_BX);
 #ifdef SMT_FULLY_ASSOCIATIVE
-  const int op1 = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int op1 = FindModifiedStack(STACK_BX);
   const int op2 = FindModifiedNextStack(op1);
 #else
-  const int op1 = nHardwareSMT::STACK_BX;
-  const int op2 = nHardwareSMT::STACK_CX;
+  const int op1 = STACK_BX;
+  const int op2 = STACK_CX;
 #endif
   Stack(dst).Push(Stack(op1).Top() + Stack(op2).Top());
   return true;
@@ -1149,13 +1160,13 @@
 //10
 bool cHardwareSMT::Inst_Val_Sub(cAvidaContext& ctx)
 {
-  const int dst = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int dst = FindModifiedStack(STACK_BX);
 #ifdef SMT_FULLY_ASSOCIATIVE
-  const int op1 = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int op1 = FindModifiedStack(STACK_BX);
   const int op2 = FindModifiedNextStack(op1);
 #else
-  const int op1 = nHardwareSMT::STACK_BX;
-  const int op2 = nHardwareSMT::STACK_CX;
+  const int op1 = STACK_BX;
+  const int op2 = STACK_CX;
 #endif
   Stack(dst).Push(Stack(op1).Top() - Stack(op2).Top());
   return true;
@@ -1164,13 +1175,13 @@
 //11
 bool cHardwareSMT::Inst_Val_Mult(cAvidaContext& ctx)
 {
-  const int dst = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int dst = FindModifiedStack(STACK_BX);
 #ifdef SMT_FULLY_ASSOCIATIVE
-  const int op1 = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int op1 = FindModifiedStack(STACK_BX);
   const int op2 = FindModifiedNextStack(op1);
 #else
-  const int op1 = nHardwareSMT::STACK_BX;
-  const int op2 = nHardwareSMT::STACK_CX;
+  const int op1 = STACK_BX;
+  const int op2 = STACK_CX;
 #endif
   Stack(dst).Push(Stack(op1).Top() * Stack(op2).Top());
   return true;
@@ -1179,13 +1190,13 @@
 //12
 bool cHardwareSMT::Inst_Val_Div(cAvidaContext& ctx)
 {
-  const int dst = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int dst = FindModifiedStack(STACK_BX);
 #ifdef SMT_FULLY_ASSOCIATIVE
-  const int op1 = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int op1 = FindModifiedStack(STACK_BX);
   const int op2 = FindModifiedNextStack(op1);
 #else
-  const int op1 = nHardwareSMT::STACK_BX;
-  const int op2 = nHardwareSMT::STACK_CX;
+  const int op1 = STACK_BX;
+  const int op2 = STACK_CX;
 #endif
   if (Stack(op2).Top() != 0) {
     if (0-INT_MAX > Stack(op1).Top() && Stack(op2).Top() == -1)
@@ -1199,10 +1210,33 @@
   return true;
 }
 
-//32
+//13
+bool cHardwareSMT::Inst_Val_Mod(cAvidaContext& ctx)
+{
+  const int dst = FindModifiedStack(STACK_BX);
+#ifdef SMT_FULLY_ASSOCIATIVE
+  const int op1 = FindModifiedStack(STACK_BX);
+  const int op2 = FindModifiedNextStack(op1);
+#else
+  const int op1 = STACK_BX;
+  const int op2 = STACK_CX;
+#endif
+  if (Stack(op2).Top() != 0) {
+    if(Stack(op2).Top() == -1)
+      Stack(dst).Push(0);
+    else
+      Stack(dst).Push(Stack(op1).Top() % Stack(op2).Top());
+  } else {
+    organism->Fault(FAULT_LOC_MATH, FAULT_TYPE_ERROR, "mod: modding by 0");
+		return false;
+  }
+  return true;
+}
+
+//14
 bool cHardwareSMT::Inst_Val_Inc(cAvidaContext& ctx)
 {
-  const int dst = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int dst = FindModifiedStack(STACK_BX);
 #ifdef SMT_FULLY_ASSOCIATIVE
   const int src = FindModifiedStack(dst);
 #else
@@ -1213,10 +1247,10 @@
   return true;
 }
 
-//33
+//15
 bool cHardwareSMT::Inst_Val_Dec(cAvidaContext& ctx)
 {
-  const int dst = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int dst = FindModifiedStack(STACK_BX);
 #ifdef SMT_FULLY_ASSOCIATIVE
   const int src = FindModifiedStack(dst);
 #else
@@ -1227,33 +1261,10 @@
   return true;
 }
 
-//34
-bool cHardwareSMT::Inst_Val_Mod(cAvidaContext& ctx)
-{
-  const int dst = FindModifiedStack(nHardwareSMT::STACK_BX);
-#ifdef SMT_FULLY_ASSOCIATIVE
-  const int op1 = FindModifiedStack(nHardwareSMT::STACK_BX);
-  const int op2 = FindModifiedNextStack(op1);
-#else
-  const int op1 = nHardwareSMT::STACK_BX;
-  const int op2 = nHardwareSMT::STACK_CX;
-#endif
-  if (Stack(op2).Top() != 0) {
-    if(Stack(op2).Top() == -1)
-      Stack(dst).Push(0);
-    else
-      Stack(dst).Push(Stack(op1).Top() % Stack(op2).Top());
-  } else {
-    organism->Fault(FAULT_LOC_MATH, FAULT_TYPE_ERROR, "mod: modding by 0");
-		return false;
-  }
-  return true;
-}
-
-//13 
+//16
 bool cHardwareSMT::Inst_SetMemory(cAvidaContext& ctx) 
 {
-  ReadLabel(nHardwareSMT::MAX_MEMSPACE_LABEL);
+  ReadLabel(MAX_MEMSPACE_LABEL);
   
   if (GetLabel().GetSize() == 0) {
     GetHead(nHardware::HEAD_FLOW).Set(0, 0);
@@ -1266,7 +1277,7 @@
   return true;
 }
 
-//14
+//17
 bool cHardwareSMT::Inst_Divide(cAvidaContext& ctx)
 {
   int mem_space_used = GetHead(nHardware::HEAD_WRITE).GetMemSpace();
@@ -1275,14 +1286,14 @@
   return Divide_Main(ctx, mem_space_used, mut_multiplier);
 }
 
-//15
+//18
 bool cHardwareSMT::Inst_HeadRead(cAvidaContext& ctx)
 {
   const int head_id = FindModifiedHead(nHardware::HEAD_READ);
 #ifdef SMT_FULLY_ASSOCIATIVE
-  const int dst = FindModifiedStack(nHardwareSMT::STACK_AX);
+  const int dst = FindModifiedStack(STACK_AX);
 #else
-  const int dst = nHardwareSMT::STACK_AX;
+  const int dst = STACK_AX;
 #endif
   
   GetHead(head_id).Adjust();
@@ -1304,14 +1315,14 @@
   return true;
 }
 
-//16
+//19
 bool cHardwareSMT::Inst_HeadWrite(cAvidaContext& ctx)
 {
   const int head_id = FindModifiedHead(nHardware::HEAD_WRITE);
 #ifdef SMT_FULLY_ASSOCIATIVE
-  const int src = FindModifiedStack(nHardwareSMT::STACK_AX);
+  const int src = FindModifiedStack(STACK_AX);
 #else
-  const int src = nHardwareSMT::STACK_AX;
+  const int src = STACK_AX;
 #endif
 
   cHeadMultiMem & active_head = GetHead(head_id);
@@ -1326,7 +1337,7 @@
   active_head.Adjust();
 	
   int value = Stack(src).Pop();
-  if (value < 0 || value >= m_inst_set->GetSize()) value = nHardwareSMT::NOPX;
+  if (value < 0 || value >= m_inst_set->GetSize()) value = NOPX;
 	
   active_head.SetInst(cInstruction(value));
   active_head.SetFlagCopied();
@@ -1336,42 +1347,10 @@
   return true;
 }
 
-//??
-bool cHardwareSMT::Inst_HeadCopy(cAvidaContext& ctx)
-{
-  // For the moment, this cannot be nop-modified.
-  cHeadMultiMem & read_head = GetHead(nHardware::HEAD_READ);
-  cHeadMultiMem & write_head = GetHead(nHardware::HEAD_WRITE);
-  sCPUStats & cpu_stats = organism->CPUStats();
-	
-  read_head.Adjust();
-  write_head.Adjust();
-	
-  // Do mutations.
-  cInstruction read_inst = read_head.GetInst();
-  if (organism->TestCopyMut(ctx)) {
-    read_inst = m_inst_set->GetRandomInst(ctx);
-    cpu_stats.mut_stats.copy_mut_count++; 
-    write_head.SetFlagMutated();
-    write_head.SetFlagCopyMut();
-    //organism->GetPhenotype().IsMutated() = true;
-  }
-  ReadInst(read_inst.GetOp());
-	
-  cpu_stats.mut_stats.copies_exec++;
-	
-  write_head.SetInst(read_inst);
-  write_head.SetFlagCopied();  // Set the copied flag...
-	
-  read_head.Advance();
-  write_head.Advance();
-  return true;
-}
-
-//17
+//20
 bool cHardwareSMT::Inst_IfEqual(cAvidaContext& ctx)      // Execute next if bx == ?cx?
 {
-  const int op1 = FindModifiedStack(nHardwareSMT::STACK_AX);
+  const int op1 = FindModifiedStack(STACK_AX);
 #ifdef SMT_FULLY_ASSOCIATIVE
   const int op2 = FindModifiedNextStack(op1);
 #else
@@ -1381,10 +1360,10 @@
   return true;
 }
 
-//18
+//21
 bool cHardwareSMT::Inst_IfNotEqual(cAvidaContext& ctx)     // Execute next if bx != ?cx?
 {
-  const int op1 = FindModifiedStack(nHardwareSMT::STACK_AX);
+  const int op1 = FindModifiedStack(STACK_AX);
 #ifdef SMT_FULLY_ASSOCIATIVE
   const int op2 = FindModifiedNextStack(op1);
 #else
@@ -1394,10 +1373,10 @@
   return true;
 }
 
-//19
+//22
 bool cHardwareSMT::Inst_IfLess(cAvidaContext& ctx)       // Execute next if ?bx? < ?cx?
 {
-  const int op1 = FindModifiedStack(nHardwareSMT::STACK_AX);
+  const int op1 = FindModifiedStack(STACK_AX);
 #ifdef SMT_FULLY_ASSOCIATIVE
   const int op2 = FindModifiedNextStack(op1);
 #else
@@ -1407,10 +1386,10 @@
   return true;
 }
 
-//20
+//23
 bool cHardwareSMT::Inst_IfGreater(cAvidaContext& ctx)       // Execute next if bx > ?cx?
 {
-  const int op1 = FindModifiedStack(nHardwareSMT::STACK_AX);
+  const int op1 = FindModifiedStack(STACK_AX);
 #ifdef SMT_FULLY_ASSOCIATIVE
   const int op2 = FindModifiedNextStack(op1);
 #else
@@ -1420,33 +1399,33 @@
   return true;
 }
 
-//21
+//24
 bool cHardwareSMT::Inst_HeadPush(cAvidaContext& ctx)
 {
   const int head_used = FindModifiedHead(nHardware::HEAD_IP);
 #ifdef SMT_FULLY_ASSOCIATIVE
-  const int dst = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int dst = FindModifiedStack(STACK_BX);
 #else
-  const int dst = nHardwareSMT::STACK_BX;
+  const int dst = STACK_BX;
 #endif
   Stack(dst).Push(GetHead(head_used).GetPosition());
   return true;
 }
 
-//22
+//25
 bool cHardwareSMT::Inst_HeadPop(cAvidaContext& ctx)
 {
   const int head_used = FindModifiedHead(nHardware::HEAD_IP);
 #ifdef SMT_FULLY_ASSOCIATIVE
-  const int src = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int src = FindModifiedStack(STACK_BX);
 #else
-  const int src = nHardwareSMT::STACK_BX;
+  const int src = STACK_BX;
 #endif
   GetHead(head_used).Set(Stack(src).Pop(), GetHead(head_used).GetMemSpace(), this);
   return true;
 }
 
-//23 
+//26
 bool cHardwareSMT::Inst_HeadMove(cAvidaContext& ctx)
 {
   const int head_used = FindModifiedHead(nHardware::HEAD_IP);
@@ -1462,35 +1441,34 @@
   return true;
 }
 
-//24
+//27
 bool cHardwareSMT::Inst_Search(cAvidaContext& ctx)
 {
   ReadLabel();
-  GetLabel().Rotate(2, nHardwareSMT::NUM_NOPS);
+  GetLabel().Rotate(2, NUM_NOPS);
   cHeadMultiMem found_pos = FindLabel(0);
   if(found_pos.GetPosition() - IP().GetPosition() == 0)
 	{
 		GetHead(nHardware::HEAD_FLOW).Set(IP().GetPosition() + 1, IP().GetMemSpace(), this);
 		// pushing zero into STACK_AX on a missed search makes it difficult to create
 		// a self-replicating organism.  @law
-		Stack(nHardwareSMT::STACK_BX).Push(0);
+		Stack(STACK_BX).Push(0);
 	}
   else
 	{
 		int search_size = found_pos.GetPosition() - IP().GetPosition() + GetLabel().GetSize() + 1;
-		Stack(nHardwareSMT::STACK_BX).Push(search_size);
-		Stack(nHardwareSMT::STACK_AX).Push(GetLabel().GetSize());
+		Stack(STACK_BX).Push(search_size);
+		Stack(STACK_AX).Push(GetLabel().GetSize());
 		GetHead(nHardware::HEAD_FLOW).Set(found_pos);
 	}  
   
   return true; 
 }
 
-//25
+//28
 bool cHardwareSMT::Inst_PushNext(cAvidaContext& ctx) 
 {
-  // @DMB - Should this allow modified next, or be eliminated in favor of just 'Push'
-  const int src = FindModifiedStack(nHardwareSMT::STACK_AX);
+  const int src = FindModifiedStack(STACK_AX);
 #ifdef SMT_FULLY_ASSOCIATIVE
   const int dst = FindModifiedNextStack(src);
 #else
@@ -1500,11 +1478,10 @@
   return true;
 }
 
-//26
+//29
 bool cHardwareSMT::Inst_PushPrevious(cAvidaContext& ctx) 
 {
-  // @DMB - Should this allow modified previous, or be eliminated in favor of just 'Push'
-  const int src = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int src = FindModifiedStack(STACK_BX);
 #ifdef SMT_FULLY_ASSOCIATIVE
   const int dst = FindModifiedPreviousStack(src);
 #else
@@ -1514,11 +1491,10 @@
   return true;
 }
 
-//27
+//30
 bool cHardwareSMT::Inst_PushComplement(cAvidaContext& ctx) 
 {
-  // @DMB - Should this allow modified complement, or be eliminated in favor of just 'Push'
-  int src = FindModifiedStack(nHardwareSMT::STACK_BX);
+  int src = FindModifiedStack(STACK_BX);
 #ifdef SMT_FULLY_ASSOCIATIVE
   const int dst = FindModifiedComplementStack(src);
 #else
@@ -1528,18 +1504,18 @@
   return true;
 }
 
-//28
+//31
 bool cHardwareSMT::Inst_ValDelete(cAvidaContext& ctx)
 {
-  int stack_used = FindModifiedStack(nHardwareSMT::STACK_BX);
+  int stack_used = FindModifiedStack(STACK_BX);
   Stack(stack_used).Pop();
   return true;
 }
 
-//29
+//32
 bool cHardwareSMT::Inst_ValCopy(cAvidaContext& ctx)
 {
-  const int dst = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int dst = FindModifiedStack(STACK_BX);
 #ifdef SMT_FULLY_ASSOCIATIVE
   const int src = FindModifiedStack(dst);
 #else
@@ -1549,37 +1525,10 @@
   return true;
 }
 
-//30
-bool cHardwareSMT::Inst_ThreadCreate(cAvidaContext& ctx)
-{
-  if (!ForkThread()) 
-    organism->Fault(FAULT_LOC_THREAD_FORK, FAULT_TYPE_FORK_TH);
-  else
-    IP().Advance();
-  return true;
-}
-
-//31
-bool cHardwareSMT::Inst_IfLabel(cAvidaContext& ctx)
-{
-  ReadLabel();
-  GetLabel().Rotate(2, nHardwareSMT::NUM_NOPS);
-  if (GetLabel() != GetReadLabel())  IP().Advance();
-  return true;
-}
-
-//35
-bool cHardwareSMT::Inst_ThreadExit(cAvidaContext& ctx)
-{
-  if (!KillThread()) organism->Fault(FAULT_LOC_THREAD_KILL, FAULT_TYPE_KILL_TH);
-  else AdvanceIP() = false;
-  return true;
-}
-
-//36
+//33
 bool cHardwareSMT::Inst_IO(cAvidaContext& ctx)
 {
-  const int dst = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int dst = FindModifiedStack(STACK_BX);
 #ifdef SMT_FULLY_ASSOCIATIVE
   const int src = FindModifiedStack(dst);
 #else
@@ -1598,6 +1547,42 @@
 }
 
 
+// --------  End Core Instruction Set --------
+
+
+// --------  Additional Instructions --------
+
+
+//34
+bool cHardwareSMT::Inst_ThreadCreate(cAvidaContext& ctx)
+{
+  ReadLabel();
+  bool success = ThreadCreate(GetLabel(), GetHead(nHardware::HEAD_FLOW).GetMemSpace());
+  if (!success) organism->Fault(FAULT_LOC_THREAD_FORK, FAULT_TYPE_FORK_TH);
+  return success;
+}
+
+//35
+bool cHardwareSMT::Inst_ThreadCancel(cAvidaContext& ctx)
+{
+  bool success = ThreadKill(m_cur_thread);
+  if (!success) organism->Fault(FAULT_LOC_THREAD_KILL, FAULT_TYPE_KILL_TH);
+  return success;
+}
+
+//36
+bool cHardwareSMT::Inst_ThreadKill(cAvidaContext& ctx)
+{
+  ReadLabel();
+  bool success = ThreadKill(GetLabel());
+  if (!success) organism->Fault(FAULT_LOC_THREAD_KILL, FAULT_TYPE_KILL_TH);
+  return success;
+}
+
+
+
+//37
+//
 // The inject instruction can be used instead of a divide command, paired
 // with an allocate.  Note that for an inject to work, one needs to have a
 // broad range for sizes allowed to be allocated.
@@ -1605,15 +1590,15 @@
 // This command will cut out from read-head to write-head.
 // It will then look at the template that follows the command and inject it
 // into the complement template found in a neighboring organism.
-
 bool cHardwareSMT::Inst_Inject(cAvidaContext& ctx)
 {
-  ReadLabel(nHardwareSMT::MAX_MEMSPACE_LABEL);
+  ReadLabel(MAX_MEMSPACE_LABEL);
   
   double mut_multiplier = 1.0;	
   return InjectParasite(ctx, mut_multiplier);
 }
 
+//38
 bool cHardwareSMT::Inst_Apoptosis(cAvidaContext& ctx)
 {
   organism->Die();
@@ -1621,9 +1606,10 @@
   return true;
 }
 
+//39
 bool cHardwareSMT::Inst_NetGet(cAvidaContext& ctx)
 {
-  const int dst = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int dst = FindModifiedStack(STACK_BX);
 #ifdef SMT_FULLY_ASSOCIATIVE
   const int seq_dst = FindModifiedNextStack(dst);
 #else
@@ -1637,25 +1623,28 @@
   return true;
 }
 
+//40
 bool cHardwareSMT::Inst_NetSend(cAvidaContext& ctx)
 {
-  const int src = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int src = FindModifiedStack(STACK_BX);
   organism->NetSend(ctx, Stack(src).Pop());
   return true;
 }
 
+//41
 bool cHardwareSMT::Inst_NetReceive(cAvidaContext& ctx)
 {
-  const int dst = FindModifiedStack(nHardwareSMT::STACK_BX);
+  const int dst = FindModifiedStack(STACK_BX);
   int val;
   bool success = organism->NetReceive(val);
   Stack(dst).Push(val);
   return success;
 }
 
+//42
 bool cHardwareSMT::Inst_NetLast(cAvidaContext& ctx)
 {
-  const int dst = FindModifiedStack(nHardwareSMT::STACK_CX);
+  const int dst = FindModifiedStack(STACK_CX);
   Stack(dst).Push(organism->NetLast());
   return true;
 }

Modified: development/source/cpu/cHardwareSMT.h
===================================================================
--- development/source/cpu/cHardwareSMT.h	2006-04-14 18:17:00 UTC (rev 616)
+++ development/source/cpu/cHardwareSMT.h	2006-04-17 14:13:25 UTC (rev 617)
@@ -10,78 +10,101 @@
 #ifndef cHardwareSMT_h
 #define cHardwareSMT_h
 
-#include <iomanip>
+#ifndef defs_h
+#include "defs.h"
+#endif
 
+#ifndef cCodeLabel_h
+#include "cCodeLabel.h"
+#endif
 #ifndef cCPUMemory_h
 #include "cCPUMemory.h"
 #endif
 #ifndef cCPUStack_h
 #include "cCPUStack.h"
 #endif
-#ifndef defs_h
-#include "defs.h"
-#endif
 #ifndef cHeadMultiMem_h
 #include "cHeadMultiMem.h"
 #endif
 #ifndef cHardwareBase_h
 #include "cHardwareBase.h"
 #endif
-#ifndef nHardwareSMT_h
-#include "nHardwareSMT.h"
-#endif
-#ifndef cHardwareSMT_Thread_h
-#include "cHardwareSMT_Thread.h"
-#endif
 #ifndef cString_h
 #include "cString.h"
 #endif
-#ifndef tManagedPointerArray_h
-#include "tManagedPointerArray.h"
+#ifndef tHashTable_h
+#include "tHashTable.h"
 #endif
 #ifndef tInstLib_h
 #include "tInstLib.h"
 #endif
-#ifndef tHashTable_h
-#include "tHashTable.h"
+#ifndef tManagedPointerArray_h
+#include "tManagedPointerArray.h"
 #endif
 
 
-class cAvidaContext;
-class cInstSet;
-class cInstLibBase;
-class cOrganism;
-class cMutation;
-class cInjectGenotype;
-
-class cCodeLabel;
-class cGenome;
-class cInjectGenotype;
-class cInstruction;
-class cInstSet;
-class cOrganism;
-
 class cHardwareSMT : public cHardwareBase
 {
 public:
   typedef bool (cHardwareSMT::*tMethod)(cAvidaContext& ctx);
 
 protected:
+  // --------  Structure Constants  --------
+  static const int NUM_LOCAL_STACKS = 3;
+  static const int NUM_GLOBAL_STACKS = 1;
+  static const int NUM_STACKS = NUM_LOCAL_STACKS + NUM_GLOBAL_STACKS;
+  static const int NUM_NOPS = 4;
+  static const int NOPX = 4;
+  static const int MAX_MEMSPACE_LABEL = 3;
+  static const int MAX_THREAD_LABEL = 3;
+
+  enum tStacks { STACK_AX = 0, STACK_BX, STACK_CX, STACK_DX };
+  
+  // --------  Performance Constants --------
+  static const int MEM_LBLS_HASH_FACTOR = 4; // Sets hast table size to (NUM_NOPS^MAX_MEMSPACE_LABEL) / FACTOR
+  static const int THREAD_LBLS_HASH_FACTOR = 4; // Sets hast table size to (NUM_NOPS^MAX_THREAD_LABEL) / FACTOR
+
+  // --------  Data Structures  --------
+  class cLocalThread
+  {
+  public:
+    cHeadMultiMem heads[nHardware::NUM_HEADS];
+    unsigned char cur_head;
+    cCPUStack local_stacks[NUM_LOCAL_STACKS];
+    
+    bool advance_ip;         // Should the IP advance after this instruction?
+    cCodeLabel read_label;
+    cCodeLabel next_label;
+    bool running;
+    
+    // If this thread was spawned by Inject, this will point to the genotype 
+    // of the parasite running the thread.  Otherwise, it will be NULL.
+    cInjectGenotype* owner;
+    
+    cLocalThread(cHardwareBase* in_hardware = NULL) { Reset(in_hardware); }
+    ~cLocalThread() { ; }
+    
+    void Reset(cHardwareBase* in_hardware, int mem_space = 0);
+  };
+  
+  // --------  Static Variables  --------
   static tInstLib<cHardwareSMT::tMethod>* s_inst_slib;
   static tInstLib<cHardwareSMT::tMethod>* initInstLib(void);
+    
 
+  // --------  Member Variables  --------
   tMethod* m_functions;
 
   // Stacks
-  cCPUStack m_global_stacks[nHardwareSMT::NUM_GLOBAL_STACKS];
+  cCPUStack m_global_stacks[NUM_GLOBAL_STACKS];
 	
   // Memory
   tManagedPointerArray<cCPUMemory> m_mem_array;
   tHashTable<int, int> m_mem_lbls;
 
   // Threads
-  tManagedPointerArray<cHardwareSMT_Thread> m_threads;
-  int thread_id_chart;
+  tManagedPointerArray<cLocalThread> m_threads;
+  tHashTable<int, int> m_thread_lbls;
   int m_cur_thread;
 	
   // Instruction costs...
@@ -103,7 +126,16 @@
   inline cCPUStack& Stack(int stack_id, int in_thread);
   inline const cCPUStack& Stack(int stack_id, int in_thread) const;
 
+  int FindModifiedStack(int default_stack);
+  int FindModifiedNextStack(int default_stack);
+  int FindModifiedPreviousStack(int default_stack);
+  int FindModifiedComplementStack(int default_stack);
+  int FindModifiedHead(int default_head);
+  int FindNextStack(int default_stack);
+  int FindPreviousStack(int default_stack);
+  int FindComplementStack(int base_stack);
   
+  
   // --------  Head Manipulation (including IP)  --------
   const bool& AdvanceIP() const { return m_threads[m_cur_thread].advance_ip; }
   bool& AdvanceIP() { return m_threads[m_cur_thread].advance_ip; }
@@ -119,19 +151,21 @@
   const cCodeLabel& GetReadLabel() const { return m_threads[m_cur_thread].read_label; }
   cCodeLabel& GetReadLabel() { return m_threads[m_cur_thread].read_label; }
 
+
+  // ---------- Memory Manipulation -----------
+  int FindMemorySpaceLabel(const cCodeLabel& label, int mem_space);
+  inline bool MemorySpaceExists(const cCodeLabel& label);
+
+  
+  // ---------- Thread Manipulation -----------
+  int ThreadCreate(const cCodeLabel& label, int mem_space);
+  bool ThreadKill(const int thread_id);
+  inline bool ThreadKill(const cCodeLabel& in_label);
+  inline int FindThreadLabel(const cCodeLabel& label);
+  bool ThreadIsRunning() { return m_threads[m_cur_thread].running; }
+  
   	
   // ---------- Instruction Helpers -----------
-  int FindModifiedStack(int default_stack);
-  int FindModifiedNextStack(int default_stack);
-  int FindModifiedPreviousStack(int default_stack);
-  int FindModifiedComplementStack(int default_stack);
-  int FindModifiedHead(int default_head);
-  int FindNextStack(int default_stack);
-  int FindPreviousStack(int default_stack);
-  int FindComplementStack(int base_stack);
-  int FindMemorySpaceLabel(const cCodeLabel& label, int mem_space);
-  bool MemorySpaceExists(const cCodeLabel& label);
-	
   bool Allocate_Necro(const int new_size);
   bool Allocate_Random(const int old_size, const int new_size);
   bool Allocate_Default(const int new_size);
@@ -203,95 +237,105 @@
   
   
   // --------  Thread Manipulation  --------
-  bool ForkThread(); // Adds a new thread based off of m_cur_thread.
-  bool KillThread(); // Kill the current thread!
-  inline void PrevThread(); // Shift the current thread in use.
-  inline void NextThread();
-  inline void SetThread(int value);
-  cInjectGenotype* GetCurThreadOwner() { return m_threads[m_cur_thread].owner; }
-  cInjectGenotype* GetThreadOwner(int in_thread) { return m_threads[in_thread].owner; }
-  void SetThreadOwner(cInjectGenotype* in_genotype) { m_threads[m_cur_thread].owner = in_genotype; }
-	
+  inline bool ThreadSelect(const int thread_id);
+  inline bool ThreadSelect(const cCodeLabel& in_label);
+  inline void ThreadPrev(); // Shift the current thread in use.
+  inline void ThreadNext();
+  cInjectGenotype* ThreadGetOwner() { return m_threads[m_cur_thread].owner; }
+  void ThreadSetOwner(cInjectGenotype* in_genotype) { m_threads[m_cur_thread].owner = in_genotype; }
+
+  int GetNumThreads() const { return m_threads.GetSize(); }
+  int GetCurThread() const { return m_cur_thread; }
+  int GetCurThreadID() const { return m_cur_thread; }
   
+  
   // --------  Parasite Stuff  --------
   int TestParasite() const;
   bool InjectHost(const cCodeLabel& in_label, const cGenome& inject_code);
-  bool InjectThread(const cCodeLabel& in_label) { return false; }
 	
   
-  // --------  Accessors  --------
-  int GetNumThreads() const     { return m_threads.GetSize(); }
-  int GetCurThread() const      { return m_cur_thread; }
-  int GetCurThreadID() const    { return m_threads[m_cur_thread].GetID(); }
-  int GetThreadDist() const {
-    if (GetNumThreads() == 1) return 0;
-    return m_threads[0].heads[nHardware::HEAD_IP].GetPosition() - m_threads[1].heads[nHardware::HEAD_IP].GetPosition();
-  }
-	
-  
 private:
   // ---------- Instruction Library -----------
-  bool Inst_ShiftR(cAvidaContext& ctx);
-  bool Inst_ShiftL(cAvidaContext& ctx);
-  bool Inst_Val_Nand(cAvidaContext& ctx);
-  bool Inst_Val_Add(cAvidaContext& ctx);
-  bool Inst_Val_Sub(cAvidaContext& ctx);
-  bool Inst_Val_Mult(cAvidaContext& ctx);
-  bool Inst_Val_Div(cAvidaContext& ctx);
-  bool Inst_Val_Mod(cAvidaContext& ctx);
-  bool Inst_Val_Inc(cAvidaContext& ctx);
-  bool Inst_Val_Dec(cAvidaContext& ctx);
-  bool Inst_SetMemory(cAvidaContext& ctx);
-  bool Inst_Divide(cAvidaContext& ctx);
-  bool Inst_HeadRead(cAvidaContext& ctx);
-  bool Inst_HeadWrite(cAvidaContext& ctx);
-  bool Inst_HeadCopy(cAvidaContext& ctx);
-  bool Inst_IfEqual(cAvidaContext& ctx);
-  bool Inst_IfNotEqual(cAvidaContext& ctx);
-  bool Inst_IfLess(cAvidaContext& ctx);
-  bool Inst_IfGreater(cAvidaContext& ctx);
-  bool Inst_HeadPush(cAvidaContext& ctx);
-  bool Inst_HeadPop(cAvidaContext& ctx);
-  bool Inst_HeadMove(cAvidaContext& ctx);
-  bool Inst_Search(cAvidaContext& ctx);
-  bool Inst_PushNext(cAvidaContext& ctx);
-  bool Inst_PushPrevious(cAvidaContext& ctx);
-  bool Inst_PushComplement(cAvidaContext& ctx);
-  bool Inst_ValDelete(cAvidaContext& ctx);
-  bool Inst_ValCopy(cAvidaContext& ctx);
-  bool Inst_ThreadCreate(cAvidaContext& ctx);
-  bool Inst_IfLabel(cAvidaContext& ctx);
-  bool Inst_ThreadExit(cAvidaContext& ctx);
-  bool Inst_IO(cAvidaContext& ctx);
-  bool Inst_Inject(cAvidaContext& ctx);
-  bool Inst_Apoptosis(cAvidaContext& ctx);
-  bool Inst_NetGet(cAvidaContext& ctx);
-  bool Inst_NetSend(cAvidaContext& ctx);
-  bool Inst_NetReceive(cAvidaContext& ctx);
-  bool Inst_NetLast(cAvidaContext& ctx);
+
+  // Core Instuction Set
+  bool Inst_ShiftR(cAvidaContext& ctx);         // 6
+  bool Inst_ShiftL(cAvidaContext& ctx);         // 7
+  bool Inst_Val_Nand(cAvidaContext& ctx);       // 8
+  bool Inst_Val_Add(cAvidaContext& ctx);        // 9
+  bool Inst_Val_Sub(cAvidaContext& ctx);        // 10
+  bool Inst_Val_Mult(cAvidaContext& ctx);       // 11
+  bool Inst_Val_Div(cAvidaContext& ctx);        // 12
+  bool Inst_Val_Mod(cAvidaContext& ctx);        // 13
+  bool Inst_Val_Inc(cAvidaContext& ctx);        // 14
+  bool Inst_Val_Dec(cAvidaContext& ctx);        // 15
+  bool Inst_SetMemory(cAvidaContext& ctx);      // 16
+  bool Inst_Divide(cAvidaContext& ctx);         // 17
+  bool Inst_HeadRead(cAvidaContext& ctx);       // 18
+  bool Inst_HeadWrite(cAvidaContext& ctx);      // 19
+  bool Inst_IfEqual(cAvidaContext& ctx);        // 20
+  bool Inst_IfNotEqual(cAvidaContext& ctx);     // 21
+  bool Inst_IfLess(cAvidaContext& ctx);         // 22
+  bool Inst_IfGreater(cAvidaContext& ctx);      // 23
+  bool Inst_HeadPush(cAvidaContext& ctx);       // 24
+  bool Inst_HeadPop(cAvidaContext& ctx);        // 25
+  bool Inst_HeadMove(cAvidaContext& ctx);       // 26
+  bool Inst_Search(cAvidaContext& ctx);         // 27
+  bool Inst_PushNext(cAvidaContext& ctx);       // 28
+  bool Inst_PushPrevious(cAvidaContext& ctx);   // 29
+  bool Inst_PushComplement(cAvidaContext& ctx); // 30
+  bool Inst_ValDelete(cAvidaContext& ctx);      // 31
+  bool Inst_ValCopy(cAvidaContext& ctx);        // 32
+  bool Inst_IO(cAvidaContext& ctx);             // 33
+  
+  // Additional Instructions
+  bool Inst_ThreadCreate(cAvidaContext& ctx);   // 34
+  bool Inst_ThreadCancel(cAvidaContext& ctx);   // 35
+  bool Inst_ThreadKill(cAvidaContext& ctx);     // 36
+  bool Inst_Inject(cAvidaContext& ctx);         // 37
+  bool Inst_Apoptosis(cAvidaContext& ctx);      // 38
+  bool Inst_NetGet(cAvidaContext& ctx);         // 39
+  bool Inst_NetSend(cAvidaContext& ctx);        // 40
+  bool Inst_NetReceive(cAvidaContext& ctx);     // 41
+  bool Inst_NetLast(cAvidaContext& ctx);        // 42
 };
 
 
-inline void cHardwareSMT::NextThread()
+inline bool cHardwareSMT::ThreadKill(const cCodeLabel& in_label)
 {
+  return ThreadKill(FindThreadLabel(in_label));
+}
+
+inline bool cHardwareSMT::ThreadSelect(const int thread_id)
+{
+  if (thread_id >= 0 && thread_id < m_threads.GetSize()) {
+    m_cur_thread = thread_id;
+    return true;
+  }
+  
+  return false;
+}
+
+inline bool cHardwareSMT::ThreadSelect(const cCodeLabel& in_label)
+{
+  return ThreadSelect(FindThreadLabel(in_label));
+}
+
+inline void cHardwareSMT::ThreadNext()
+{
   m_cur_thread++;
   if (m_cur_thread >= GetNumThreads()) m_cur_thread = 0;
 }
 
-inline void cHardwareSMT::PrevThread()
+inline void cHardwareSMT::ThreadPrev()
 {
   if (m_cur_thread == 0) m_cur_thread = GetNumThreads() - 1;
   else m_cur_thread--;
 }
 
-inline void cHardwareSMT::SetThread(int value)
-{
-  if (value>=0 && value < GetNumThreads()) m_cur_thread = value;
-}
 
 inline int cHardwareSMT::GetStack(int depth, int stack_id, int in_thread) const
 {
-  if(stack_id<0 || stack_id > nHardwareSMT::NUM_STACKS) stack_id=0;
+  if(stack_id<0 || stack_id > NUM_STACKS) stack_id=0;
   
   if(in_thread==-1)
     in_thread=m_cur_thread;
@@ -301,42 +345,42 @@
 
 inline cCPUStack& cHardwareSMT::Stack(int stack_id)
 {
-  if(stack_id >= nHardwareSMT::NUM_STACKS) stack_id = 0;
-  if(stack_id < nHardwareSMT::NUM_LOCAL_STACKS)
+  if(stack_id >= NUM_STACKS) stack_id = 0;
+  if(stack_id < NUM_LOCAL_STACKS)
     return m_threads[m_cur_thread].local_stacks[stack_id];
   else
-    return m_global_stacks[stack_id % nHardwareSMT::NUM_LOCAL_STACKS];
+    return m_global_stacks[stack_id % NUM_LOCAL_STACKS];
 }
 
 inline const cCPUStack& cHardwareSMT::Stack(int stack_id) const 
 {
-  if(stack_id >= nHardwareSMT::NUM_STACKS) stack_id = 0;
-  if(stack_id < nHardwareSMT::NUM_LOCAL_STACKS)
+  if(stack_id >= NUM_STACKS) stack_id = 0;
+  if(stack_id < NUM_LOCAL_STACKS)
     return m_threads[m_cur_thread].local_stacks[stack_id];
   else
-    return m_global_stacks[stack_id % nHardwareSMT::NUM_LOCAL_STACKS];
+    return m_global_stacks[stack_id % NUM_LOCAL_STACKS];
 }
 
 inline cCPUStack& cHardwareSMT::Stack(int stack_id, int in_thread) 
 {
-  if(stack_id >= nHardwareSMT::NUM_STACKS) stack_id = 0;
+  if(stack_id >= NUM_STACKS) stack_id = 0;
   if(in_thread >= m_threads.GetSize()) in_thread = m_cur_thread;
 	
-  if(stack_id < nHardwareSMT::NUM_LOCAL_STACKS)
+  if(stack_id < NUM_LOCAL_STACKS)
     return m_threads[in_thread].local_stacks[stack_id];
   else
-    return m_global_stacks[stack_id % nHardwareSMT::NUM_LOCAL_STACKS];
+    return m_global_stacks[stack_id % NUM_LOCAL_STACKS];
 }
 
 inline const cCPUStack& cHardwareSMT::Stack(int stack_id, int in_thread) const 
 {
-  if(stack_id >= nHardwareSMT::NUM_STACKS) stack_id = 0;
+  if(stack_id >= NUM_STACKS) stack_id = 0;
   if(in_thread >= m_threads.GetSize()) in_thread = m_cur_thread;
 	
-  if(stack_id < nHardwareSMT::NUM_LOCAL_STACKS)
+  if(stack_id < NUM_LOCAL_STACKS)
     return m_threads[in_thread].local_stacks[stack_id];
   else
-    return m_global_stacks[stack_id % nHardwareSMT::NUM_LOCAL_STACKS];
+    return m_global_stacks[stack_id % NUM_LOCAL_STACKS];
 }
 
 inline int cHardwareSMT::NormalizeMemSpace(int mem_space) const
@@ -346,4 +390,20 @@
   return mem_space;
 }
 
+inline bool cHardwareSMT::MemorySpaceExists(const cCodeLabel& label)
+{
+  int null;
+  if (label.GetSize() == 0 || m_mem_lbls.Find(label.AsInt(NUM_NOPS), null)) return true;
+  return false;
+}
+
+inline int cHardwareSMT::FindThreadLabel(const cCodeLabel& label)
+{
+  int thread_id = -1;
+  if (label.GetSize() == 0) return 0;
+  m_thread_lbls.Find(label.AsInt(NUM_NOPS), thread_id);
+  return thread_id;
+}
+
+
 #endif

Deleted: development/source/cpu/cHardwareSMT_Thread.cc
===================================================================
--- development/source/cpu/cHardwareSMT_Thread.cc	2006-04-14 18:17:00 UTC (rev 616)
+++ development/source/cpu/cHardwareSMT_Thread.cc	2006-04-17 14:13:25 UTC (rev 617)
@@ -1,55 +0,0 @@
-/*
- *  cHardwareSMT_Thread.cc
- *  Avida
- *
- *  Created by David on 6/4/05.
- *  Copyright 2005-2006 Michigan State University. All rights reserved.
- *
- */
-
-#include "cHardwareSMT_Thread.h"
-
-using namespace std;
-
-cHardwareSMT_Thread::cHardwareSMT_Thread(cHardwareBase* in_hardware, int _id)
-{
-  Reset(in_hardware, _id);
-}
-
-cHardwareSMT_Thread::cHardwareSMT_Thread(const cHardwareSMT_Thread& in_thread, int _id)
-{
-	id = _id;
-	if (id == -1) id = in_thread.id;
-	for (int i = 0; i < nHardwareSMT::NUM_LOCAL_STACKS; i++) {
-		local_stacks[i] = in_thread.local_stacks[i];
-	}
-	for (int i = 0; i < nHardware::NUM_HEADS; i++) {
-		heads[i] = in_thread.heads[i];
-	}
-	owner = in_thread.owner;
-}
-
-void cHardwareSMT_Thread::operator=(const cHardwareSMT_Thread& in_thread)
-{
-  id = in_thread.id;
-  for (int i = 0; i < nHardwareSMT::NUM_LOCAL_STACKS; i++) {
-    local_stacks[i] = in_thread.local_stacks[i];
-  }
-  for (int i = 0; i < nHardware::NUM_HEADS; i++) {
-    heads[i] = in_thread.heads[i];
-  }
-  owner = in_thread.owner;
-}
-
-void cHardwareSMT_Thread::Reset(cHardwareBase* in_hardware, int _id, int mem_space)
-{
-  id = _id;
-	
-  for (int i = 0; i < nHardwareSMT::NUM_LOCAL_STACKS; i++) local_stacks[i].Clear();
-  for (int i = 0; i < nHardware::NUM_HEADS; i++) heads[i].Reset(mem_space, in_hardware);
-	
-  cur_head = nHardware::HEAD_IP;
-  read_label.Clear();
-  next_label.Clear();
-  owner = NULL;
-}

Deleted: development/source/cpu/cHardwareSMT_Thread.h
===================================================================
--- development/source/cpu/cHardwareSMT_Thread.h	2006-04-14 18:17:00 UTC (rev 616)
+++ development/source/cpu/cHardwareSMT_Thread.h	2006-04-17 14:13:25 UTC (rev 617)
@@ -1,60 +0,0 @@
-/*
- *  cHardwareSMT_Thread.h
- *  Avida
- *
- *  Created by David on 6/4/05.
- *  Copyright 2005-2006 Michigan State University. All rights reserved.
- *
- */
-
-#ifndef cHardwareSMT_Thread_h
-#define cHardwareSMT_Thread_h
-
-#include <iostream>
-
-#ifndef cCodeLabel_h
-#include "cCodeLabel.h"
-#endif
-#ifndef cCPUStack_h
-#include "cCPUStack.h"
-#endif
-#ifndef cHeadMultiMem_h
-#include "cHeadMultiMem.h"
-#endif
-#ifndef nHardwareSMT_h
-#include "nHardwareSMT.h"
-#endif
-
-class cHardwareBase;
-class cInjectGenotype;
-
-class cHardwareSMT_Thread
-{
-private:
-  int id;
-
-public:
-  cHeadMultiMem heads[nHardware::NUM_HEADS];
-  unsigned char cur_head;
-  cCPUStack local_stacks[nHardwareSMT::NUM_LOCAL_STACKS];
-	
-  bool advance_ip;         // Should the IP advance after this instruction?
-  cCodeLabel read_label;
-  cCodeLabel next_label;
-  // If this thread was spawned by Inject, this will point to the genotype 
-  // of the parasite running the thread.  Otherwise, it will be NULL.
-  cInjectGenotype* owner;
-
-  
-  cHardwareSMT_Thread(cHardwareBase* in_hardware = NULL, int _id = -1);
-  cHardwareSMT_Thread(const cHardwareSMT_Thread& in_thread, int _id = -1);
-  ~cHardwareSMT_Thread() { ; }
-
-  void operator=(const cHardwareSMT_Thread& in_thread);
-	
-  void Reset(cHardwareBase* in_hardware, int _id, int mem_space = 0);
-  int GetID() const { return id; }
-  void SetID(int _id) { id = _id; }
-};
-
-#endif

Deleted: development/source/cpu/nHardwareSMT.h
===================================================================
--- development/source/cpu/nHardwareSMT.h	2006-04-14 18:17:00 UTC (rev 616)
+++ development/source/cpu/nHardwareSMT.h	2006-04-17 14:13:25 UTC (rev 617)
@@ -1,29 +0,0 @@
-/*
- *  nHardwareSMT.h
- *  Avida
- *
- *  Created by David on 6/4/05.
- *  Copyright 2005-2006 Michigan State University. All rights reserved.
- *
- */
-
-#ifndef nHardwareSMT_h
-#define nHardwareSMT_h
-
-namespace nHardwareSMT
-{
-  static const int NUM_LOCAL_STACKS = 3;
-  static const int NUM_GLOBAL_STACKS = 1;
-  static const int NUM_STACKS = NUM_LOCAL_STACKS + NUM_GLOBAL_STACKS;
-  
-  enum tStacks { STACK_AX = 0, STACK_BX, STACK_CX, STACK_DX };
-  
-  static const int NUM_NOPS = 4;
-  static const int NOPX = 4;
-  static const int MAX_MEMSPACE_LABEL = 3;
-  
-  // Performance Constants
-  static const int MEM_LBLS_HASH_FACTOR = 4; // Sets hast table size to (NUM_NOPS^MAX_MEMSPACE_LABEL) / FACTOR
-}
-
-#endif

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2006-04-14 18:17:00 UTC (rev 616)
+++ development/source/main/cPopulation.cc	2006-04-17 14:13:25 UTC (rev 617)
@@ -389,7 +389,7 @@
   if (injected_code.GetSize() == 0) return false;
   
   cHardwareBase& parent_cpu = parent.GetHardware();
-  cInjectGenotype* parent_genotype = parent_cpu.GetCurThreadOwner();
+  cInjectGenotype* parent_genotype = parent_cpu.ThreadGetOwner();
   
   const int parent_id = parent.GetOrgInterface().GetCellID();
   assert(parent_id >= 0 && parent_id < cell_array.GetSize());
@@ -405,9 +405,10 @@
   
   if (child_cpu.GetNumThreads() == m_world->GetConfig().MAX_CPU_THREADS.Get()) return false;
   
-  cInjectGenotype* child_genotype = parent_genotype; // @DMB - uh, WTF?  This is not creating a copy. Should it?
   
   if (target_organism->InjectHost(parent_cpu.GetLabel(), injected_code)) {
+    cInjectGenotype* child_genotype = parent_genotype;
+
     // If the parent genotype is not correct for the child, adjust it.
     if (parent_genotype == NULL || parent_genotype->GetGenome() != injected_code) {
       child_genotype = m_world->GetClassificationManager().GetInjectGenotype(injected_code, parent_genotype);
@@ -415,7 +416,7 @@
     
     target_organism->AddParasite(child_genotype);
     child_genotype->AddParasite();
-    child_cpu.SetThreadOwner(child_genotype);
+    child_cpu.ThreadSetOwner(child_genotype);
     m_world->GetClassificationManager().AdjustInjectGenotype(*child_genotype);
   }
   else
@@ -426,13 +427,13 @@
 
 bool cPopulation::ActivateInject(const int cell_id, const cGenome& injected_code)
 {
-  cInjectGenotype * child_genotype = m_world->GetClassificationManager().GetInjectGenotype(injected_code);
+  cInjectGenotype* child_genotype = m_world->GetClassificationManager().GetInjectGenotype(injected_code);
   cHardwareBase& child_cpu = cell_array[cell_id].GetOrganism()->GetHardware();
   if(cell_array[cell_id].GetOrganism()->InjectHost(cCodeLabel(), injected_code))
   {
     cell_array[cell_id].GetOrganism()->AddParasite(child_genotype);
     child_genotype->AddParasite();
-    child_cpu.SetThreadOwner(child_genotype);
+    child_cpu.ThreadSetOwner(child_genotype);
     m_world->GetClassificationManager().AdjustInjectGenotype(*child_genotype);
   }
   else
@@ -1963,7 +1964,10 @@
 	      cHardwareBase& cpu = cell_array[x].GetOrganism()->GetHardware();
 	      outfile << x << " ";
 	      outfile << cell_array[x].GetOrganism()->GetGenotype()->GetID() << " ";
-	      temp = cpu.GetThreadOwner(1);
+        int prev_thread = cpu.GetCurThread();
+        cpu.ThreadSelect(1);
+	      temp = cpu.ThreadGetOwner();
+        cpu.ThreadSelect(prev_thread);
 	      assert(temp!=NULL);
 	      outfile << temp->GetID() << endl;	      
 	    }

Modified: development/support/config/inst_set.smt
===================================================================
--- development/support/config/inst_set.smt	2006-04-14 18:17:00 UTC (rev 616)
+++ development/support/config/inst_set.smt	2006-04-17 14:13:25 UTC (rev 617)
@@ -1,3 +1,4 @@
+# Core Instruction Set
 Nop-A         1  #1  (a)	
 Nop-B         1  #2  (b)
 Nop-C         1  #3  (c)
@@ -2,33 +3,41 @@
 Nop-D         1  #4  (d)
-Nop-X         1  #5  (e)
-Val-Shift-R   1  #6  (f)
-Val-Shift-L   1  #7  (g)
-Val-Nand      1  #8  (h)
-Val-Add       1  #9  (i)
-Val-Sub       1  #10 (j)
-Val-Mult      1  #11 (k)
-Val-Div       1  #12 (l)
-Val-Mod       1  #13 (m)
-Val-Inc       1  #14 (n)
-Val-Dec       1  #15 (o)
-SetMemory    	1  #16 (p)
-Divide        1  #17 (q)
-Inst-Read     1  #18 (r)
-Inst-Write    1  #19 (s)
-If-Equal      1  #20 (t)
-If-Not-Equal  1  #21 (u)
-If-Less       1  #22 (v)
-If-Greater    1  #23 (w)
-Head-Push     1  #24 (x)
-Head-Pop      1  #25 (y)
-Head-Move     1  #26 (z)
-Search        1  #27 (A)
-Push-Next     1  #28 (B)
-Push-Prev     1  #29 (C)
-Push-Comp     1  #30 (D)
-Val-Delete    1  #31 (E)
-Val-Copy      1  #32 (F)
-#ThreadFork   1  #33 ()
-#ThreadKill   1  #34 ()
-IO            1  #35 (G)
-#Inject       1  #36 ()
+Val-Shift-R   1  #5  (e)
+Val-Shift-L   1  #6  (f)
+Val-Nand      1  #7  (g)
+Val-Add       1  #8  (h)
+Val-Sub       1  #9  (i)
+Val-Mult      1  #10 (j)
+Val-Div       1  #11 (k)
+Val-Mod       1  #12 (l)
+Val-Inc       1  #13 (m)
+Val-Dec       1  #14 (n)
+SetMemory    	1  #15 (o)
+Divide        1  #16 (p)
+Inst-Read     1  #17 (q)
+Inst-Write    1  #18 (r)
+If-Equal      1  #19 (s)
+If-Not-Equal  1  #20 (t)
+If-Less       1  #21 (u)
+If-Greater    1  #22 (v)
+Head-Push     1  #23 (w)
+Head-Pop      1  #24 (x)
+Head-Move     1  #25 (y)
+Search        1  #26 (z)
+Push-Next     1  #27 (A)
+Push-Prev     1  #28 (B)
+Push-Comp     1  #29 (C)
+Val-Delete    1  #30 (D)
+Val-Copy      1  #31 (E)
+IO            1  #32 (F)
+
+# Additional Instructions - Disabled by Default
+#Nop-X         1  #33 ()
+#Thread-Create 1  #34 ()
+#Thread-Cancel 1  #35 ()
+#Thread-Kill   1  #36 ()
+#Inject        1  #37 ()
+#Apoptosis     1  #38 ()
+#Net-Get       1  #39 ()
+#Net-Send      1  #40 ()
+#Net-Receive   1  #41 ()
+#Net-Last      1  #42 ()

Modified: development/support/config/organism.smt
===================================================================
--- development/support/config/organism.smt	2006-04-14 18:17:00 UTC (rev 616)
+++ development/support/config/organism.smt	2006-04-17 14:13:25 UTC (rev 617)
@@ -1,5 +1,3 @@
-# SAMPLE ORGANISM:
-#
 Search       #  1:  Find organism end.
 Nop-C        #  2:  - Match CD:AB
 Nop-D
@@ -90,9 +88,6 @@
 Nop-C        #  8:
 Nop-C        #  8:
 Nop-C        #  8:
-Nop-C        #  8:
-Nop-C        #  8:
-Nop-C        #  8:
 Search       #  9:  Drop flow head at start of copy loop
 Inst-Read    # 10:
 Inst-Write   # 11: 

Modified: development/support/config/organism.smtx
===================================================================
--- development/support/config/organism.smtx	2006-04-14 18:17:00 UTC (rev 616)
+++ development/support/config/organism.smtx	2006-04-17 14:13:25 UTC (rev 617)
@@ -1,5 +1,3 @@
-# SAMPLE ORGANISM:
-#
 Search       #  1:  Find organism end.
 Nop-C        #  2:  - Match CD:AB
 Nop-D
@@ -90,9 +88,6 @@
 Nop-X        #  8:
 Nop-X        #  8:
 Nop-X        #  8:
-Nop-X        #  8:
-Nop-X        #  8:
-Nop-X        #  8:
 Search       #  9:  Drop flow head at start of copy loop
 Inst-Read    # 10:
 Inst-Write   # 11: 




More information about the Avida-cvs mailing list