Index: trunk/pdns/pdns/pdns_recursor.cc
===================================================================
--- trunk/pdns/pdns/pdns_recursor.cc	(revision 1508)
+++ trunk/pdns/pdns/pdns_recursor.cc	(revision 1511)
@@ -75,4 +75,5 @@
 bool g_logCommonErrors;
 __thread shared_ptr<PowerDNSLua>* t_pdl;
+__thread RemoteKeeper* t_remotes;
 
 RecursorControlChannel s_rcc; // only active in thread 0
@@ -759,5 +760,5 @@
     }
 
-    g_stats.addRemote(addr);
+    t_remotes->addRemote(addr);
     if(t_allowFrom && !t_allowFrom->match(&addr)) {
       if(!g_quiet) 
@@ -800,5 +801,5 @@
   if((len=recvfrom(fd, data, sizeof(data), 0, (sockaddr *)&fromaddr, &addrlen)) >= 0) {
 
-    g_stats.addRemote(fromaddr);
+    t_remotes->addRemote(fromaddr);
 
     if(t_allowFrom && !t_allowFrom->match(&fromaddr)) {
@@ -1176,4 +1177,12 @@
 }
 
+vector<ComboAddress>& operator+=(vector<ComboAddress>&a, const vector<ComboAddress>& b)
+{
+  a.insert(a.end(), b.begin(), b.end());
+  return a;
+}
+
+
+
 template<class T> T broadcastAccFunction(const boost::function<T*()>& func, bool skipSelf)
 {
@@ -1213,4 +1222,5 @@
 template string broadcastAccFunction(const boost::function<string*()>& fun, bool skipSelf); // explicit instantiation
 template uint64_t broadcastAccFunction(const boost::function<uint64_t*()>& fun, bool skipSelf); // explicit instantiation
+template vector<ComboAddress> broadcastAccFunction(const boost::function<vector<ComboAddress> *()>& fun, bool skipSelf); // explicit instantiation
 
 void handleRCC(int fd, FDMultiplexer::funcparam_t& var)
@@ -1618,7 +1628,5 @@
   g_initialDomainMap = parseAuthAndForwards();
  
-  //  g_stats.remotes.resize(::arg().asNum("remotes-ringbuffer-entries")); XXX FIXME NEEDS TO BE REDONE FOR "MULTITHREADING"
-  if(!g_stats.remotes.empty())
-    memset(&g_stats.remotes[0], 0, g_stats.remotes.size() * sizeof(RecursorStats::remotes_t::value_type));
+    
   g_logCommonErrors=::arg().mustDo("log-common-errors");
   
@@ -1703,4 +1711,11 @@
     exit(99);
   }
+  
+  t_remotes = new RemoteKeeper();
+  t_remotes->remotes.resize(::arg().asNum("remotes-ringbuffer-entries") / g_numThreads); 
+  
+  if(!t_remotes->remotes.empty())
+    memset(&t_remotes->remotes[0], 0, t_remotes->remotes.size() * sizeof(RemoteKeeper::remotes_t::value_type));
+  
   
   MT=new MTasker<PacketID,string>(::arg().asNum("stack-size"));
