Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/client.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/client.cpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/client.cpp	(revision 1764)
@@ -355,4 +355,7 @@
       CXios::setXiosComm(xiosGlobalComm) ;
 
+      MPI_Comm commUnfree ;
+      MPI_Comm_dup(clientComm, &commUnfree ) ;
+ 
     }
 
@@ -732,4 +735,7 @@
       CTimer::get("XIOS init/finalize",false).suspend() ;
       CTimer::get("XIOS").suspend() ;
+      
+      CXios::finalizeDaemonsManager() ;
+
       if (!is_MPI_Initialized)
       {
@@ -748,4 +754,6 @@
       report(0)<< " Memory report : increasing it by a factor will increase performance, depending of the volume of data wrote in file at each time step of the file"<<endl ;
       report(100)<<CTimer::getAllCumulatedTime()<<endl ;
+    
+      
     }
     
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/context_client.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/context_client.cpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/context_client.cpp	(revision 1764)
@@ -262,5 +262,6 @@
           {
             for (int i = 0; i < context->serverPrimServer.size(); ++i)  context->serverPrimServer[i]->listen();
-            CServer::contextEventLoop(false) ; // avoid dead-lock at finalize...
+ //ym           CServer::contextEventLoop(false) ; // avoid dead-lock at finalize...
+            context->globalEventLoop() ;
           }
 
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/context_server.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/context_server.cpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/context_server.cpp	(revision 1764)
@@ -30,5 +30,5 @@
   using namespace std ;
 
-  CContextServer::CContextServer(CContext* parent,MPI_Comm intraComm_,MPI_Comm interComm_)
+  CContextServer::CContextServer(CContext* parent,MPI_Comm intraComm_,MPI_Comm interComm_) : eventScheduler_(nullptr), isProcessingEvent_(false)
   {
     context=parent;
@@ -53,5 +53,5 @@
     if (contextInfo.serviceType != CServicesManager::CLIENT) // we must have an event scheduler => to be retrieve from the associated services
     {
-      eventScheduler_=CXios::getPoolRessource()->getService(contextInfo.serviceId,contextInfo.partitionId)->getEventScheduler() ;
+      if (!isAttachedModeEnabled()) eventScheduler_=CXios::getPoolRessource()->getService(contextInfo.serviceId,contextInfo.partitionId)->getEventScheduler() ;
     }
 
@@ -321,5 +321,6 @@
     CEventServer* event;
     
-    if (context->isProcessingEvent()) return ;
+//    if (context->isProcessingEvent()) return ;
+    if (isProcessingEvent_) return ;
 
     it=events.find(currentTimeLine);
@@ -330,21 +331,23 @@
       if (event->isFull())
       {
-        if (!scheduled && CServer::eventScheduler) // Skip event scheduling for attached mode and reception on client side
+        if (!scheduled && eventScheduler_) // Skip event scheduling for attached mode and reception on client side
         {
-          CServer::eventScheduler->registerEvent(currentTimeLine,hashId);
+          eventScheduler_->registerEvent(currentTimeLine,hashId);
           scheduled=true;
         }
-        else if (!CServer::eventScheduler || CServer::eventScheduler->queryEvent(currentTimeLine,hashId) )
+        else if (!eventScheduler_ || eventScheduler_->queryEvent(currentTimeLine,hashId) )
         {
          // When using attached mode, synchronise the processes to avoid that differents event be scheduled by differents processes
          // The best way to properly solve this problem will be to use the event scheduler also in attached mode
          // for now just set up a MPI barrier
-         if (!CServer::eventScheduler && CXios::isServer) MPI_Barrier(intraComm) ;
-
-         context->setProcessingEvent() ;
+         if (!eventScheduler_ && CXios::isServer) MPI_Barrier(intraComm) ;
+
+//         context->setProcessingEvent() ;
+         isProcessingEvent_=true ;
          CTimer::get("Process events").resume();
          dispatchEvent(*event);
          CTimer::get("Process events").suspend();
-         context->unsetProcessingEvent() ;
+         isProcessingEvent_=false ;
+//         context->unsetProcessingEvent() ;
          pendingEvent=false;
          delete event;
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/context_server.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/context_server.hpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/context_server.hpp	(revision 1764)
@@ -66,4 +66,5 @@
       vector<MPI_Win> windows ; //! one sided mpi windows to expose client buffers to servers ; No memory will be attached on server side.
       CEventScheduler* eventScheduler_ ;
+      bool isProcessingEvent_ ;
   } ;
 
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/cxios.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/cxios.cpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/cxios.cpp	(revision 1764)
@@ -341,4 +341,26 @@
   }
 
+  
+  void CXios::finalizeRessourcesManager()
+  {
+    delete ressourcesManager_;
+  }
+
+  void CXios::finalizeServicesManager()
+  {
+    delete servicesManager_  ;
+  }
+
+  void CXios::finalizeContextsManager()
+  {
+    delete contextsManager_  ;
+  }
+  
+  void CXios::finalizeDaemonsManager()
+  {
+    delete daemonsManager_  ;
+  }
+  
+
   CPoolRessource* CXios::getPoolRessource(void)
   {
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/cxios.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/cxios.hpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/cxios.hpp	(revision 1764)
@@ -91,4 +91,9 @@
      static void launchRessourcesManager(bool isXiosServer) ;
      
+     static void finalizeServicesManager() ;
+     static void finalizeContextsManager() ;
+     static void finalizeDaemonsManager() ;
+     static void finalizeRessourcesManager() ;
+
      static CRessourcesManager* getRessourcesManager(void) { return ressourcesManager_ ;}
      static CServicesManager*   getServicesManager(void) { return servicesManager_ ;}
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/contexts_manager.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/contexts_manager.cpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/contexts_manager.cpp	(revision 1764)
@@ -36,4 +36,11 @@
   }
 
+
+  CContextsManager::~CContextsManager()
+  {
+    delete winNotify_ ;
+    delete winContexts_ ;
+  }
+
   bool CContextsManager::createServerContext(const std::string& poolId, const std::string& serviceId, const int& partitionId,
                                              const string& contextId, bool wait)
@@ -48,5 +55,5 @@
       while (!ok) 
       {
-        CXios::getDaemonsManager()->eventLoop() ;
+        CXios::getDaemonsManager()->servicesEventLoop() ;
         ok=servicesManager->getServiceLeader(poolId, serviceId, partitionId, serviceLeader) ;
       }
@@ -79,5 +86,5 @@
       while (!ok) 
       {
-        CXios::getDaemonsManager()->eventLoop() ;
+        CXios::getDaemonsManager()->servicesEventLoop() ;
         ok=CXios::getServicesManager()->getServiceType(poolId,serviceId, 0, type) ;
         if (ok) ok=getContextLeader(getServerContextName(poolId, serviceId, partitionId, type, contextId), contextLeader) ;
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/contexts_manager.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/contexts_manager.hpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/contexts_manager.hpp	(revision 1764)
@@ -28,4 +28,6 @@
  
     CContextsManager(bool isXiosServer) ;
+    ~CContextsManager() ;
+    
     bool createServerContext(const std::string& poolId, const std::string& serviceId, const int& partitionId, const string& contextId, bool wait=true) ;
 /*    bool createServerContextIntercomm(const std::string& poolId, const std::string& serviceId, const int& partitionId, const std::string& contextId,
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/daemons_manager.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/daemons_manager.cpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/daemons_manager.cpp	(revision 1764)
@@ -26,4 +26,11 @@
   }
 
+  CDaemonsManager::~CDaemonsManager()
+  {
+    CXios::finalizeContextsManager() ;
+    CXios::finalizeServicesManager() ;
+    CXios::finalizeRessourcesManager() ;
+  }
+
   bool CDaemonsManager::eventLoop(void)
   {
@@ -31,7 +38,16 @@
     CXios::getServicesManager()->eventLoop() ;
     CXios::getContextsManager()->eventLoop() ;
-    if (isServer_) return CServer::getServersRessource()->eventLoop() ;
-    else  return CXios::getPoolRessource()->eventLoop() ;
+    if (isServer_) return CServer::getServersRessource()->eventLoop(false) ;
+    else  return CXios::getPoolRessource()->eventLoop(false) ;
   }
+  
+  bool CDaemonsManager::servicesEventLoop(void)
+  {
+    CXios::getRessourcesManager()->eventLoop() ;
+    CXios::getServicesManager()->eventLoop() ;
+    CXios::getContextsManager()->eventLoop() ;
+    if (isServer_) return CServer::getServersRessource()->eventLoop(true) ;
+    else  return CXios::getPoolRessource()->eventLoop(true) ;
+  } 
 
 }
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/daemons_manager.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/daemons_manager.hpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/daemons_manager.hpp	(revision 1764)
@@ -11,6 +11,8 @@
 
     CDaemonsManager(bool isXiosServer) ;
+    ~CDaemonsManager() ;
 
     bool eventLoop(void) ;
+    bool servicesEventLoop(void) ;
     
     private:
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/pool_ressource.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/pool_ressource.cpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/pool_ressource.cpp	(revision 1764)
@@ -100,10 +100,10 @@
   }
 
-  bool CPoolRessource::eventLoop(void)
+  bool CPoolRessource::eventLoop(bool serviceOnly)
   {
     checkCreateServiceNotification() ;
     for (auto it=services_.begin(); it!=services_.end() ; ++it) 
     {
-      if (it->second->eventLoop())
+      if (it->second->eventLoop(serviceOnly))
       {
         services_.erase(it) ;
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/pool_ressource.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/pool_ressource.hpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/pool_ressource.hpp	(revision 1764)
@@ -31,5 +31,5 @@
     void checkCreateServiceNotification(void) ;
     void createNewService(const std::string& serviceId, int type, int size, int nbPartitions, bool in) ;
-     bool eventLoop(void) ;
+     bool eventLoop(bool serviceOnly=false) ;
     CService* getService(const std::string serviceId, int partitionId) { return services_[make_tuple(serviceId,partitionId)]; }
     void finalizeSignal(void) ;
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/ressources_manager.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/ressources_manager.cpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/ressources_manager.cpp	(revision 1764)
@@ -34,5 +34,10 @@
     MPI_Barrier(xiosComm_)  ;    
   }
-
+  
+  CRessourcesManager::~CRessourcesManager()
+  {
+    delete winNotify_ ;
+    delete winRessources_ ;
+  } 
 
   void CRessourcesManager::createPool(const string& poolId, int size)
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/ressources_manager.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/ressources_manager.hpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/ressources_manager.hpp	(revision 1764)
@@ -28,4 +28,5 @@
     
     CRessourcesManager(bool isXiosServer) ;
+    ~CRessourcesManager() ;
 
     void eventLoop(void) ;
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/server_context.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/server_context.cpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/server_context.cpp	(revision 1764)
@@ -15,5 +15,6 @@
 
   CServerContext::CServerContext(CService* parentService, MPI_Comm contextComm, const std::string& poolId, const std::string& serviceId, 
-                                 const int& partitionId, const std::string& contextId) : finalizeSignal_(false), parentService_(parentService)
+                                 const int& partitionId, const std::string& contextId) : finalizeSignal_(false), parentService_(parentService),
+                                 hasNotification_(false)
   {
    int localRank, globalRank, commSize ;
@@ -48,5 +49,9 @@
   }
 
-  
+  CServerContext::~CServerContext()
+  {
+
+  } 
+
   bool CServerContext::createIntercomm(const string& poolId, const string& serviceId, const int& partitionId, const string& contextId, 
                                        const MPI_Comm& intraComm, MPI_Comm& interCommClient, MPI_Comm& interCommServer, bool wait)
@@ -75,14 +80,25 @@
     }
     
-    auto eventScheduler=parentService_->getEventScheduler() ;
-    std::hash<string> hashString ;
-    size_t hashId = hashString(name_) ;
-    size_t currentTimeLine=0 ;
-    eventScheduler->registerEvent(currentTimeLine,hashId); 
-
-    while (!eventScheduler->queryEvent(currentTimeLine,hashId))
-    {
-       CXios::getDaemonsManager()->eventLoop() ;
-    }  
+    MPI_Request req ;
+    MPI_Status status ;
+    MPI_Ibarrier(intraComm,&req) ;
+    
+    int flag=false ;
+    while(!flag) 
+    {
+      CXios::getDaemonsManager()->servicesEventLoop() ;
+      MPI_Test(&req,&flag,&status) ;
+    }
+//    auto eventScheduler=parentService_->getEventScheduler() ;
+//    std::hash<string> hashString ;
+//    size_t hashId = hashString(name_) ;
+//    size_t currentTimeLine=0 ;
+//    eventScheduler->registerEvent(currentTimeLine,hashId); 
+//
+//    while (!eventScheduler->queryEvent(currentTimeLine,hashId))
+//    {
+//       CXios::getDaemonsManager()->servicesEventLoop() ;
+//       eventScheduler->checkEvent() ;
+//    }  
     
     MPI_Bcast(&ok, 1, MPI_INT, 0, intraComm) ;
@@ -90,4 +106,13 @@
     if (ok)  
     {
+      int globalRank ;
+      MPI_Comm_rank(xiosComm_,&globalRank) ;
+      MPI_Bcast(&contextLeader, 1, MPI_INT, 0, intraComm) ;
+      
+      int overlap, nOverlap ;
+      if (contextLeader==globalRank) overlap=1 ;
+      else overlap=0 ;
+      MPI_Allreduce(&overlap, &nOverlap, 1, MPI_INT, MPI_SUM, contextComm_) ;
+/*
       int overlap  ;
       if (get<0>(overlapedComm_[name_])) overlap=1 ;
@@ -98,6 +123,9 @@
       int commSize ;
       MPI_Comm_size(contextComm_,&commSize ) ;
-      if (nOverlap==commSize)
-      {
+*/
+      if (nOverlap> 0 )
+      {
+        while (get<0>(overlapedComm_[name_])==false) CXios::getDaemonsManager()->servicesEventLoop() ;
+        isAttachedMode_=true ;
         cout<<"CServerContext::createIntercomm : total overlap ==> context in attached mode"<<endl ;
         interCommClient=newInterCommClient ;
@@ -107,4 +135,5 @@
       { 
         cout<<"CServerContext::createIntercomm : No overlap ==> context in server mode"<<endl ;
+        isAttachedMode_=false ;
         MPI_Intercomm_create(intraComm, 0, xiosComm_, contextLeader, 3141, &interCommClient) ;
         MPI_Comm_dup(interCommClient, &interCommServer) ;
@@ -128,6 +157,6 @@
      for(int rank=0; rank<commSize; rank++)
      {
-       notifyType_=NOTIFY_CREATE_INTERCOMM ;
-       notifyCreateIntercomm_ = make_tuple(remoteLeader, sourceContext) ;
+       notifyOutType_=NOTIFY_CREATE_INTERCOMM ;
+       notifyOutCreateIntercomm_ = make_tuple(remoteLeader, sourceContext) ;
        sendNotification(rank) ;
      }
@@ -147,8 +176,8 @@
     buffer.realloc(maxBufferSize_) ;
     
-    if (notifyType_==NOTIFY_CREATE_INTERCOMM)
-    {
-      auto& arg=notifyCreateIntercomm_ ;
-      buffer << notifyType_ << std::get<0>(arg)<<std::get<1>(arg) ;
+    if (notifyOutType_==NOTIFY_CREATE_INTERCOMM)
+    {
+      auto& arg=notifyOutCreateIntercomm_ ;
+      buffer << notifyOutType_ << std::get<0>(arg)<<std::get<1>(arg) ;
     }
   }
@@ -156,11 +185,11 @@
   void CServerContext::notificationsDumpIn(CBufferIn& buffer)
   {
-    if (buffer.bufferSize() == 0) notifyType_= NOTIFY_NOTHING ;
+    if (buffer.bufferSize() == 0) notifyInType_= NOTIFY_NOTHING ;
     else
     {
-      buffer>>notifyType_;
-      if (notifyType_==NOTIFY_CREATE_INTERCOMM)
-      {
-        auto& arg=notifyCreateIntercomm_ ;
+      buffer>>notifyInType_;
+      if (notifyInType_==NOTIFY_CREATE_INTERCOMM)
+      {
+        auto& arg=notifyInCreateIntercomm_ ;
         buffer >> std::get<0>(arg)>> std::get<1>(arg) ;
       }
@@ -170,17 +199,42 @@
   void CServerContext::checkNotifications(void)
   {
-    int commRank ;
-    MPI_Comm_rank(contextComm_, &commRank) ;
-    winNotify_->lockWindow(commRank,0) ;
-    winNotify_->popFromWindow(commRank, this, &CServerContext::notificationsDumpIn) ;
-    winNotify_->unlockWindow(commRank,0) ;
-    if (notifyType_==NOTIFY_CREATE_INTERCOMM) createIntercomm() ;
-  }
-
-  bool CServerContext::eventLoop(void)
+    if (!hasNotification_)
+    {
+      int commRank ;
+      MPI_Comm_rank(contextComm_, &commRank) ;
+      winNotify_->lockWindow(commRank,0) ;
+      winNotify_->popFromWindow(commRank, this, &CServerContext::notificationsDumpIn) ;
+      winNotify_->unlockWindow(commRank,0) ;
+      
+      if (notifyInType_!= NOTIFY_NOTHING)
+      {
+        hasNotification_=true ;
+        auto eventScheduler=parentService_->getEventScheduler() ;
+        std::hash<string> hashString ;
+        size_t hashId = hashString(name_) ;
+        size_t currentTimeLine=0 ;
+        eventScheduler->registerEvent(currentTimeLine,hashId); 
+      }
+    }
+    
+    if (hasNotification_)
+    {
+      auto eventScheduler=parentService_->getEventScheduler() ;
+      std::hash<string> hashString ;
+      size_t hashId = hashString(name_) ;
+      size_t currentTimeLine=0 ;
+      if (eventScheduler->queryEvent(currentTimeLine,hashId))
+      {
+        if (notifyInType_==NOTIFY_CREATE_INTERCOMM) createIntercomm() ;
+        hasNotification_=false ;
+      }
+    }
+  }
+
+  bool CServerContext::eventLoop(bool serviceOnly)
   {
     bool finished=false ;
-    checkNotifications() ;
-    if (context_!=nullptr)  
+    if (winNotify_!=nullptr) checkNotifications() ;
+    if (!serviceOnly && context_!=nullptr)  
     {
       if (context_->eventLoop())
@@ -198,6 +252,7 @@
   {
      MPI_Comm interCommServer, interCommClient ;
-     int remoteLeader=get<0>(notifyCreateIntercomm_) ;
-     string sourceContext=get<1>(notifyCreateIntercomm_) ;
+     auto& arg=notifyInCreateIntercomm_ ;
+     int remoteLeader=get<0>(arg) ;
+     string sourceContext=get<1>(arg) ;
 
      auto it=overlapedComm_.find(sourceContext) ;
@@ -215,5 +270,6 @@
     if (nOverlap==commSize)
     {
-      cout<<"CServerContext::createIntercomm : total overlap ==> context in attached mode"<<endl ;
+      info(10)<<"CServerContext::createIntercomm : total overlap ==> context in attached mode"<<endl ;
+      isAttachedMode_=true ;
       interCommClient=get<2>(it->second) ;
       interCommServer=get<1>(it->second) ;
@@ -224,5 +280,6 @@
     else if (nOverlap==0)
     { 
-      cout<<"CServerContext::createIntercomm : No overlap ==> context in server mode"<<endl ;
+      info(10)<<"CServerContext::createIntercomm : No overlap ==> context in server mode"<<endl ;
+      isAttachedMode_=false ;
       MPI_Intercomm_create(contextComm_, 0, xiosComm_, remoteLeader, 3141, &interCommServer) ;
       MPI_Comm_dup(interCommServer,&interCommClient) ;
@@ -233,14 +290,21 @@
     else
     {
-      cout<<"CServerContext::createIntercomm : partial overlap ==> not managed"<<endl ;
+      ERROR("void CServerContext::createIntercomm(void)",<<"CServerContext::createIntercomm : partial overlap ==> not managed") ;
     }
    
   }
 
+  void CServerContext::freeComm(void)
+  {
+    delete winNotify_ ;
+    winNotify_=nullptr ;
+    MPI_Comm_free(&contextComm_) ;
+    // don't forget intercomm -> later
+  }
+  
   void CServerContext::finalizeSignal(void)
   {
     finalizeSignal_=true ;
   }
-   
 
 }
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/server_context.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/server_context.hpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/server_context.hpp	(revision 1764)
@@ -18,4 +18,5 @@
     CServerContext(CService* parentService, MPI_Comm contextComm, const std::string& poolId, const std::string& serviceId, 
                   const int& partitionId, const std::string& contextId) ;
+    ~CServerContext() ;
 
     bool createIntercomm(const string& poolId, const string& serviceId, const int& partitionId, const string& contextId, 
@@ -26,8 +27,10 @@
     void checkNotifications(void) ;
 
-    bool eventLoop(void) ;
+    bool eventLoop(bool serviceOnly=false) ;
     void notificationsDumpOut(CBufferOut& buffer) ;
     void notificationsDumpIn(CBufferIn& buffer) ;
     void finalizeSignal(void) ;
+    void freeComm(void) ;
+    bool isAttachedMode(void) { return isAttachedMode_ ;}
     private:
     void createIntercomm(void) ;
@@ -47,10 +50,12 @@
     const size_t maxBufferSize_=1024*1024 ;
     CWindowManager* winNotify_ ;
-    int notifyType_ ;
-    tuple<int, std::string> notifyCreateIntercomm_ ;
+    int notifyInType_, notifyOutType_ ;
+    tuple<int, std::string> notifyInCreateIntercomm_, notifyOutCreateIntercomm_ ;
 
     const int localLeader_=0 ;
     int globalLeader_ ;
     bool finalizeSignal_ ;
+    bool hasNotification_ ;
+    bool isAttachedMode_ ;
 
     friend class CWindowManager ;
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/servers_ressource.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/servers_ressource.cpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/servers_ressource.cpp	(revision 1764)
@@ -57,6 +57,6 @@
        }
        
-       notifyType_=NOTIFY_CREATE_POOL ;
-       notifyCreatePool_ = make_tuple(poolId, isPartOf) ;
+       notifyOutType_=NOTIFY_CREATE_POOL ;
+       notifyOutCreatePool_ = make_tuple(poolId, isPartOf) ;
        sendNotification(freeRessourcesRank_[i]) ;
     }
@@ -71,5 +71,5 @@
     for(int rank=0; rank<commSize;rank++)
     { 
-      notifyType_=NOTIFY_FINALIZE ;
+      notifyOutType_=NOTIFY_FINALIZE ;
       sendNotification(rank) ;
     }
@@ -89,33 +89,33 @@
     buffer.realloc(maxBufferSize_) ;
     
-    if (notifyType_==NOTIFY_CREATE_POOL)
+    if (notifyOutType_==NOTIFY_CREATE_POOL)
     {
-      auto& arg=notifyCreatePool_ ;
-      buffer << notifyType_ << std::get<0>(arg) << std::get<1>(arg) ;
+      auto& arg=notifyOutCreatePool_ ;
+      buffer << notifyOutType_ << std::get<0>(arg) << std::get<1>(arg) ;
     }
-    else if (notifyType_==NOTIFY_FINALIZE) buffer << notifyType_ ;
+    else if (notifyOutType_==NOTIFY_FINALIZE) buffer << notifyOutType_ ;
   }
 
   void CServersRessource::notificationsDumpIn(CBufferIn& buffer)
   {
-    if (buffer.bufferSize() == 0) notifyType_= NOTIFY_NOTHING ;
+    if (buffer.bufferSize() == 0) notifyInType_= NOTIFY_NOTHING ;
     else
     {
-      buffer>>notifyType_;
-      if (notifyType_==NOTIFY_CREATE_POOL)
+      buffer>>notifyInType_;
+      if (notifyInType_==NOTIFY_CREATE_POOL)
       {
-        auto& arg=notifyCreatePool_ ;
+        auto& arg=notifyInCreatePool_ ;
         buffer >> std::get<0>(arg) >> std::get<1>(arg)  ;
       }
-      else if (notifyType_==NOTIFY_FINALIZE) { /*nothing to do*/}
+      else if (notifyInType_==NOTIFY_FINALIZE) { /*nothing to do*/}
     }
   }
 
-  bool CServersRessource::eventLoop()
+  bool CServersRessource::eventLoop(bool serviceOnly)
   {
     checkNotifications() ;
     if (poolRessource_!=nullptr) 
     {
-      if (poolRessource_->eventLoop())
+      if (poolRessource_->eventLoop(serviceOnly))
       {
         poolRessource_=nullptr ;
@@ -135,11 +135,11 @@
     winNotify_->popFromWindow(commRank, this, &CServersRessource::notificationsDumpIn) ;
     winNotify_->unlockWindow(commRank,0) ;
-    if (notifyType_==NOTIFY_CREATE_POOL) createPool() ;
-    else if (notifyType_==NOTIFY_FINALIZE) finalizeSignal() ;
+    if (notifyInType_==NOTIFY_CREATE_POOL) createPool() ;
+    else if (notifyInType_==NOTIFY_FINALIZE) finalizeSignal() ;
   }
 
   void CServersRessource::createPool(void)
   {
-    auto& arg=notifyCreatePool_ ;
+    auto& arg=notifyInCreatePool_ ;
     string poolId=get<0>(arg) ;
     bool isPartOf=get<1>(arg) ;
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/servers_ressource.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/servers_ressource.hpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/servers_ressource.hpp	(revision 1764)
@@ -26,5 +26,5 @@
     void createPool(const string& poolId, const int size) ;
     void createPool(void) ;
-    bool eventLoop(void) ;
+    bool eventLoop(bool serviceOnly=false) ;
     void sendNotification(int rank) ;
     void notificationsDumpOut(CBufferOut& buffer) ;
@@ -44,6 +44,7 @@
     const size_t maxBufferSize_=1024*1024 ;
     CWindowManager* winNotify_ ;
-    int notifyType_ ;
-    std::tuple<std::string, bool> notifyCreatePool_ ;
+    
+    int notifyInType_,notifyOutType_ ;
+    std::tuple<std::string, bool> notifyInCreatePool_,notifyOutCreatePool_ ;
     CPoolRessource* poolRessource_ ;
     bool finalizeSignal_ ;
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/services.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/services.cpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/services.cpp	(revision 1764)
@@ -10,5 +10,5 @@
   CService::CService(MPI_Comm serviceComm, const std::string& poolId, const std::string& serviceId, const int& partitionId, 
                      int type, int nbPartitions) : finalizeSignal_(false), eventScheduler_(nullptr), poolId_(poolId), serviceId_(serviceId),
-                                                   partitionId_(partitionId), type_(type), nbPartitions_(nbPartitions)
+                                                   partitionId_(partitionId), type_(type), nbPartitions_(nbPartitions), hasNotification_(false)
 
 
@@ -34,4 +34,8 @@
     }
     eventScheduler_ = new CEventScheduler(serviceComm_) ;
+
+    ostringstream oss;
+    oss<<partitionId;
+    name_= poolId+"::"+serviceId+"_"+oss.str();
   }
 
@@ -41,5 +45,10 @@
     MPI_Comm_size(serviceComm_, &commSize) ;
     
-    for(int rank=0; rank<commSize; rank++) createContextNotify(rank, poolId, serviceId, partitionId, contextId) ;
+    for(int rank=0; rank<commSize; rank++) 
+    {
+      notifyOutType_=NOTIFY_CREATE_CONTEXT ;
+      notifyOutCreateContext_ = make_tuple(poolId, serviceId, partitionId, contextId) ;
+      sendNotification(rank) ;
+    }
   }
 /*
@@ -87,11 +96,13 @@
   }
 
-  bool CService::eventLoop(void)
-  {
-    checkCreateContextNotification() ;
+  bool CService::eventLoop(bool serviceOnly)
+  {
+    //checkCreateContextNotification() ;
+    checkNotifications() ;
+
     eventScheduler_->checkEvent() ;
     for(auto it=contexts_.begin();it!=contexts_.end();++it) 
     {
-      if (it->second->eventLoop())
+      if (it->second->eventLoop(serviceOnly))
       {
         contexts_.erase(it) ;
@@ -105,4 +116,78 @@
   }
 
+  void CService::sendNotification(int rank)
+  {
+    winNotify_->lockWindow(rank,0) ;
+    winNotify_->pushToWindow(rank, this, &CService::notificationsDumpOut) ;
+    winNotify_->unlockWindow(rank,0) ;
+  }
+
+  
+  void CService::notificationsDumpOut(CBufferOut& buffer)
+  {
+    
+    buffer.realloc(maxBufferSize_) ;
+    
+    if (notifyOutType_==NOTIFY_CREATE_CONTEXT)
+    {
+      auto& arg=notifyOutCreateContext_ ;
+      buffer << notifyOutType_ << std::get<0>(arg)<<std::get<1>(arg) << std::get<2>(arg)<<std::get<3>(arg) ;
+    }
+  }
+
+  void CService::notificationsDumpIn(CBufferIn& buffer)
+  {
+    if (buffer.bufferSize() == 0) notifyInType_= NOTIFY_NOTHING ;
+    else
+    {
+      buffer>>notifyInType_;
+      if (notifyInType_==NOTIFY_CREATE_CONTEXT)
+      {
+        info(10)<<"NotifyDumpOut"<<endl ;
+        auto& arg=notifyInCreateContext_ ;
+        buffer >> std::get<0>(arg)>> std::get<1>(arg) >> std::get<2>(arg)>> std::get<3>(arg);
+      }
+    }
+  }
+
+
+
+
+  void CService::checkNotifications(void)
+  {
+    if (!hasNotification_)
+    {
+      int commRank ;
+      MPI_Comm_rank(serviceComm_, &commRank) ;
+      winNotify_->lockWindow(commRank,0) ;
+      winNotify_->popFromWindow(commRank, this, &CService::notificationsDumpIn) ;
+      winNotify_->unlockWindow(commRank,0) ;
+      
+      if (notifyInType_!= NOTIFY_NOTHING)
+      {
+        hasNotification_=true ;
+        std::hash<string> hashString ;
+        size_t hashId = hashString(name_) ;
+        size_t currentTimeLine=0 ;
+        eventScheduler_->registerEvent(currentTimeLine,hashId); 
+      }
+    }
+    
+    if (hasNotification_)
+    {
+      std::hash<string> hashString ;
+      size_t hashId = hashString(name_) ;
+      size_t currentTimeLine=0 ;
+      if (eventScheduler_->queryEvent(currentTimeLine,hashId))
+      {
+        if (notifyInType_==NOTIFY_CREATE_CONTEXT) createContext() ;
+        hasNotification_=false ;
+      }
+    }
+  }
+
+
+
+
   void CService::checkCreateContextNotification(void)
   {
@@ -122,4 +207,15 @@
   }
 
+  void CService::createContext(void)
+   {
+     auto& arg=notifyInCreateContext_ ;
+     string poolId = get<0>(arg) ;
+     string& serviceId = get<1>(arg) ;
+     int partitionId = get<2>(arg) ;
+     string contextId = get<3>(arg) ;
+     contexts_[contextId] = new CServerContext(this, serviceComm_, poolId, serviceId, partitionId, contextId) ; 
+   }
+
+   //to remove
    void CService::createNewContext(const std::string& poolId, const std::string& serviceId, const int& partitionId, const std::string& contextId)
    {
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/services.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/services.hpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/services.hpp	(revision 1764)
@@ -16,7 +16,10 @@
     public:
     
+    const int NOTIFY_NOTHING=0 ;
+    const int NOTIFY_CREATE_CONTEXT=1 ;
+
     CService(MPI_Comm serviceComm, const std::string& poolId, const std::string& serviceId, const int& partitionId, 
              int type, int nbPartitions) ;
-    bool eventLoop(void) ;
+    bool eventLoop(bool serviceOnly=false) ;
     void createContext(const std::string& poolId, const std::string& serviceId, const int& partitionId, const std::string& contextId) ;
     void checkCreateContextNotification(void) ;
@@ -36,13 +39,26 @@
 
     private:
-    
+    void sendNotification(int rank) ;
+    void notificationsDumpOut(CBufferOut& buffer) ;
+    void notificationsDumpIn(CBufferIn& buffer) ;
+    void checkNotifications(void) ;
+    void createContext(void) ;
+
     MPI_Comm serviceComm_ ;
     MPI_Comm globalComm_ ;
-   
+
     const size_t maxBufferSize_=1024*1024 ;
     const int localLeader_=0 ;
     int globalLeader_ ;
     CWindowManager* winNotify_ ;
+    
+    std::string name_ ;
+
     std::list<std::tuple<std::string, std::string, int, std::string>> notifications_;
+    
+    bool hasNotification_ ;
+    int notifyInType_,notifyOutType_ ;
+    std::tuple<std::string, std::string, int, std::string> notifyInCreateContext_, notifyOutCreateContext_ ;
+
     std::map<std::string, CServerContext*> contexts_ ;
     bool finalizeSignal_ ;
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/services_manager.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/services_manager.cpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/services_manager.cpp	(revision 1764)
@@ -42,4 +42,10 @@
   }
 
+  CServicesManager::~CServicesManager()
+  {
+    delete winNotify_ ;
+    delete winServices_ ;
+  }
+
   bool CServicesManager::createServices(const std::string& poolId, const std::string& serviceId, 
                                         int type, int size, int nbPartitions, bool wait) 
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/services_manager.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/services_manager.hpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/services_manager.hpp	(revision 1764)
@@ -27,4 +27,6 @@
     
     CServicesManager(bool isXiosServer) ;
+    ~CServicesManager() ;
+    
     bool createServices(const std::string& poolId, const std::string& serviceId, int type, int size, int nbPartition, bool wait=true) ;
     void createServicesNotify(int rank, const string& serviceId, int type, int size, int nbPartitions) ;
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/window_manager.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/window_manager.hpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/window_manager.hpp	(revision 1764)
@@ -126,4 +126,8 @@
     }
 
+    ~CWindowManager()
+    {
+      MPI_Win_free(&window_) ;
+    }
   } ;
 }
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/node/context.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/node/context.cpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/node/context.cpp	(revision 1764)
@@ -36,5 +36,5 @@
       , isPostProcessed(false), finalized(false)
       , idServer_(), client(nullptr), server(nullptr)
-      , allProcessed(false), countChildCtx_(0), isProcessingEvent_(false)
+      , allProcessed(false), countChildContextFinalized_(0), isProcessingEvent_(false)
 
    { /* Ne rien faire de plus */ }
@@ -45,5 +45,5 @@
       , isPostProcessed(false), finalized(false)
       , idServer_(), client(nullptr), server(nullptr)
-      , allProcessed(false), countChildCtx_(0), isProcessingEvent_(false)
+      , allProcessed(false), countChildContextFinalized_(0), isProcessingEvent_(false)
    { /* Ne rien faire de plus */ }
 
@@ -475,5 +475,5 @@
     MPI_Comm_dup(intraComm_, &intraCommClient);
     comms.push_back(intraCommClient);
-    
+    // attached_mode=parentServerContext_->isAttachedMode() ; //ym probably inherited from source context
     server = new CContextServer(this,intraComm_, interCommServer); // check if we need to dupl. intraComm_ ?
     client = new CContextClient(this,intraCommClient,interCommClient);
@@ -687,5 +687,10 @@
   CATCH_DUMP_ATTR
 
-
+  
+  void CContext::globalEventLoop(void)
+  {
+    CXios::getDaemonsManager()->eventLoop() ;
+    setCurrent(getId()) ;
+  }
 
 
@@ -693,32 +698,16 @@
    TRY
    {
-      if (hasClient && !hasServer) // For now we only use server level 1 to read data
+      registryOut->hierarchicalGatherRegistry() ;
+      if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ;
+
+      if (hasClient && !hasServer)
       {
-        doPreTimestepOperationsForEnabledReadModeFiles();
-      }
-     // Send registry upon calling the function the first time
-     if (countChildCtx_ == 0) if (hasClient) sendRegistry() ;
-
-     // Client:
-     // (1) blocking send context finalize to its server
-     // (2) blocking receive context finalize from its server
-     // (3) some memory deallocations
-     if (CXios::isClient)
-     {
-       // Make sure that client (model) enters the loop only once
-       if (countChildCtx_ < 1)
-       {
-         ++countChildCtx_;
-
-         info(100)<<"DEBUG: context "<<getId()<<" Send client finalize"<<endl ;
-         client->finalize();
-         info(100)<<"DEBUG: context "<<getId()<<" Client finalize sent"<<endl ;
-         while (client->havePendingRequests()) client->checkBuffers();
-         
-         info(100)<<"DEBUG: context "<<getId()<<" no pending request ok"<<endl ;
-         while (!server->hasFinished())
-           server->eventLoop();
-        info(100)<<"DEBUG: context "<<getId()<<" server has finished"<<endl ;
-        
+        doPreTimestepOperationsForEnabledReadModeFiles(); // For now we only use server level 1 to read data
+
+        info(100)<<"DEBUG: context "<<getId()<<" Send client finalize"<<endl ;
+        client->finalize();
+        info(100)<<"DEBUG: context "<<getId()<<" Client finalize sent"<<endl ;
+        while (client->havePendingRequests()) client->checkBuffers();
+        info(100)<<"DEBUG: context "<<getId()<<" no pending request ok"<<endl ;
         bool notifiedFinalized=false ;
         do
@@ -727,28 +716,8 @@
         } while (!notifiedFinalized) ;
         client->releaseBuffers();
-
-         if (hasServer) // Mode attache
-         {
-           closeAllFile();
-           registryOut->hierarchicalGatherRegistry() ;
-           if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ;
-         }
-
-         //! Deallocate client buffers
-//         client->releaseBuffers();
         info(100)<<"DEBUG: context "<<getId()<<" release client ok"<<endl ;
-         //! Free internally allocated communicators
-         for (std::list<MPI_Comm>::iterator it = comms.begin(); it != comms.end(); ++it)
-           MPI_Comm_free(&(*it));
-         comms.clear();
-
-         info(20)<<"CContext: Context <"<<getId()<<"> is finalized."<<endl;
-       }
-     }
-     else if (CXios::isServer)
-     {
-       // First context finalize message received from a model
-       // Send context finalize to its child contexts (if any)
-       if (countChildCtx_ == 0)
+      }
+      else if (hasClient && hasServer)
+      {
          for (int i = 0; i < clientPrimServer.size(); ++i)
          {
@@ -764,64 +733,21 @@
            do
            {
-//             clientPrimServer[i]->checkBuffers();
              notifiedFinalized=clientPrimServer[i]->isNotifiedFinalized() ;
            } while (!notifiedFinalized) ;
            clientPrimServer[i]->releaseBuffers();
          }
-           
-
-       // (Last) context finalized message received
-       if (countChildCtx_ == clientPrimServer.size())
-       {
-         // Blocking send of context finalize message to its client (e.g. primary server or model)
-         info(100)<<"DEBUG: context "<<getId()<<" Send client finalize"<<endl ;
-         client->finalize();
-         info(100)<<"DEBUG: context "<<getId()<<" Client finalize sent"<<endl ;
-         bool bufferReleased;
-         do
-         {
-           client->checkBuffers();
-           bufferReleased = !client->havePendingRequests();
-         } while (!bufferReleased);
-         
-         bool notifiedFinalized=false ;
-         do
-         {
-  //         client->checkBuffers();
-           notifiedFinalized=client->isNotifiedFinalized() ;
-         } while (!notifiedFinalized) ;
-         client->releaseBuffers();
-         
-         finalized = true;
-         info(100)<<"DEBUG: context "<<getId()<<" bufferRelease OK"<<endl ;
-         
-         closeAllFile(); // Just move to here to make sure that server-level 1 can close files
+         closeAllFile();
+
+      }
+      else if (!hasClient && hasServer)
+      {
+        closeAllFile();
+      }
+
+      freeComms() ;
         
-        /*  ym
-         if (hasServer && !hasClient)
-         {           
-           registryOut->hierarchicalGatherRegistry() ;
-           if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ;
-         }
-        */
-
-         //! Deallocate client buffers
-//         client->releaseBuffers();
-         info(100)<<"DEBUG: context "<<getId()<<" client release"<<endl ;
-
-/*         
-         for (int i = 0; i < clientPrimServer.size(); ++i)
-           clientPrimServer[i]->releaseBuffers();
-*/
-         //! Free internally allocated communicators
-         for (std::list<MPI_Comm>::iterator it = comms.begin(); it != comms.end(); ++it)
-           MPI_Comm_free(&(*it));
-         comms.clear();
-
-         info(20)<<"CContext: Context <"<<getId()<<"> is finalized."<<endl;
-       }
-
-       ++countChildCtx_;
-     }
+      parentServerContext_->freeComm() ;
+      finalized = true;
+      info(20)<<"CContext: Context <"<<getId()<<"> is finalized."<<endl;
    }
    CATCH_DUMP_ATTR
@@ -833,4 +759,6 @@
    TRY
    {
+      int countChildCtx_ ; // ym temporary
+
       if (hasClient && !hasServer) // For now we only use server level 1 to read data
       {
@@ -2555,4 +2483,43 @@
   CATCH_DUMP_ATTR
 
+  
+  void CContext::sendFinalizeClient(CContextClient* contextClient, const string& contextClientId)
+  TRY
+  {
+    CEventClient event(getType(),EVENT_ID_CONTEXT_FINALIZE_CLIENT);
+    if (contextClient->isServerLeader())
+    {
+      CMessage msg;
+      msg<<contextClientId ;
+      const std::list<int>& ranks = contextClient->getRanksServerLeader();
+      for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
+           event.push(*itRank,1,msg);
+      contextClient->sendEvent(event);
+    }
+    else contextClient->sendEvent(event);
+  }
+  CATCH_DUMP_ATTR
+
+ 
+  void CContext::recvFinalizeClient(CEventServer& event)
+  TRY
+  {
+    CBufferIn* buffer=event.subEvents.begin()->buffer;
+    string id;
+    *buffer>>id;
+    get(id)->recvFinalizeClient(*buffer);
+  }
+  CATCH
+
+  void CContext::recvFinalizeClient(CBufferIn& buffer)
+  TRY
+  {
+    countChildContextFinalized_++ ;
+  }
+  CATCH_DUMP_ATTR
+
+
+
+
   /*!
   * \fn bool CContext::isFinalized(void)
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/node/context.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/node/context.hpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/node/context.hpp	(revision 1764)
@@ -53,5 +53,6 @@
            EVENT_ID_POST_PROCESS, EVENT_ID_SEND_REGISTRY,
            EVENT_ID_POST_PROCESS_GLOBAL_ATTRIBUTES,
-           EVENT_ID_PROCESS_GRID_ENABLED_FIELDS
+           EVENT_ID_PROCESS_GRID_ENABLED_FIELDS,
+           EVENT_ID_CONTEXT_FINALIZE_CLIENT,
          };
 
@@ -106,7 +107,9 @@
          bool checkBuffersAndListen(bool enableEventsProcessing=true);
          bool eventLoop(bool enableEventsProcessing=true);
+         void globalEventLoop(void);
 
          // Finalize a context
          void finalize(void);
+
          void finalize_old(void);
          bool isFinalized(void);
@@ -170,4 +173,6 @@
          //!< after be gathered to the root process of the context, merged registry is sent to the root process of the servers
          void sendRegistry(void) ;
+         void sendFinalizeClient(CContextClient* contextClient, const string& contextClientId);
+
 
          const StdString& getIdServer();
@@ -191,5 +196,7 @@
          static void recvRegistry(CEventServer& event) ;
          void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers
-
+         static void recvFinalizeClient(CEventServer& event) ;
+         void recvFinalizeClient(CBufferIn& buffer);
+         
          void freeComms(void);                  //!< Free internally allcoated communicators
          void releaseClientBuffers(void);       //! Deallocate buffers allocated by clientContexts
@@ -281,5 +288,5 @@
          bool allProcessed;
          bool finalized;
-         int countChildCtx_;        //!< Counter of child contexts (for now it is the number of secondary server pools)
+         int countChildContextFinalized_;        //!< Counter of child contexts (for now it is the number of secondary server pools)
          StdString idServer_;
          CGarbageCollector garbageCollector;
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/node/field.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/node/field.cpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/node/field.cpp	(revision 1764)
@@ -635,5 +635,6 @@
 
 //ym          context->checkBuffersAndListen();
-            context->eventLoop();
+//ym            context->eventLoop();
+          context->globalEventLoop();
 
           timer.suspend();
Index: /XIOS/dev/dev_ym/XIOS_SERVICES/src/server.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_SERVICES/src/server.cpp	(revision 1763)
+++ /XIOS/dev/dev_ym/XIOS_SERVICES/src/server.cpp	(revision 1764)
@@ -711,4 +711,6 @@
 //      MPI_Comm_free(&intraComm);
 
+      CXios::finalizeDaemonsManager();
+      
       if (!is_MPI_Initialized)
       {
