Index: trunk/SophyaPI/PIext/piacmd.cc
===================================================================
--- trunk/SophyaPI/PIext/piacmd.cc	(revision 2474)
+++ trunk/SophyaPI/PIext/piacmd.cc	(revision 2486)
@@ -180,4 +180,7 @@
 
 InitializeHelpWindowMenu();
+// <ZThread>  Thread control attributes
+fg_thrstop = false;
+fg_threxe = false; 
 }
 
@@ -195,4 +198,38 @@
 }
 
+
+/* --Methode-- */
+void PIACmd::AddInputLine(string const & line)
+{
+  mutx_inps.lock();
+  inputlines.push(line);
+  mutx_inps.unlock();
+  mutx_inps.broadcast();
+}
+
+/* --Methode-- */
+void PIACmd::StopThread()
+{
+  fg_thrstop = true;
+  mutx_inps.broadcast();
+}
+
+/* --Methode-- */
+void PIACmd::run()
+{
+  cout << " DBG-PIACmd::run() -- DEBUT " << endl;
+  while (!fg_thrstop) {
+    mutx_inps.lock();
+    while (inputlines.empty()) { 
+      fg_threxe = false;
+      mutx_inps.wait();
+    }
+    string line = inputlines.top();
+    inputlines.pop();
+    fg_threxe = true;
+    mutx_inps.unlock();
+    Interpret(line);
+  }
+}
 
 /* --Methode-- */
Index: trunk/SophyaPI/PIext/piacmd.h
===================================================================
--- trunk/SophyaPI/PIext/piacmd.h	(revision 2474)
+++ trunk/SophyaPI/PIext/piacmd.h	(revision 2486)
@@ -11,4 +11,6 @@
 #include <string>
 #include <vector>
+#include <stack>
+#include "zthread.h"
 
 #include "dlftypes.h"
@@ -29,5 +31,5 @@
 
 
-class PIACmd : public Commander  {
+class PIACmd : public Commander, public ZThread  {
 public:
   //  static PIACmd*	GetInterpreter();
@@ -36,4 +38,11 @@
   virtual		~PIACmd();
 
+  // Thread execution  <ZThread>
+  virtual void          run();
+  void                  AddInputLine(string const & line);
+  void                  StopThread();
+  inline  bool          isRunning(int& ninp) 
+    { ninp = inputlines.size(); return fg_threxe; }
+  // ---- FIN ---- Thread execution  <ZThread>
 
   void                   ShowHelpWindow();
@@ -77,4 +86,11 @@
   CxxExecWind* cxxexwin;
   CxxOptionWind* cxxoptwin;
+
+// Stack d'entree et controle de thread
+  stack<string> inputlines;
+  bool fg_thrstop;
+  ZMutex mutx_inps;
+  bool fg_threxe;
+
 };
 
Index: trunk/SophyaPI/PIext/pistdimgapp.cc
===================================================================
--- trunk/SophyaPI/PIext/pistdimgapp.cc	(revision 2474)
+++ trunk/SophyaPI/PIext/pistdimgapp.cc	(revision 2486)
@@ -90,5 +90,5 @@
 /* --Methode-- */
 PIStdImgApp::PIStdImgApp(int narg, char* arg[])
-: PIApplication(420, 320, narg, arg)
+  : PIApplication(420, 320, narg, arg) , resusg(ResourceUsage::RU_All)
 {
 
@@ -188,5 +188,5 @@
 // le widget zoom, colormap, stats, ...
 
-int bss = 100+mFgScSz*15;
+int bss = 105+mFgScSz*15;
 
 int statc_szy = bss+10+14+mFgScSz*2+5; 
@@ -202,23 +202,29 @@
 
 // Widget pour affichage des stats / ressources 
-lab_mem = new PILabel(statcont, "memlab", msx-2*(bss+20), 20, 2*bss+20, 10);
+lab_mem = new PILabel(statcont, "memlab", msx-2*(bss+20), 20, 2*bss+20, 5);
 lab_mem->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free); 
 lab_mem->SetLabel("MemoryUsage");
 lab_mem->SetForegroundColor(PI_Red);
 lab_mem->SetBorderWidth(1);
-therm_mem = new PIThermometer(statcont, "memtherm", msx-2*(bss+20), 20, 2*bss+20, 35);
+therm_mem = new PIThermometer(statcont, "memtherm", msx-2*(bss+20), 15, 2*bss+20, 30);
 therm_mem->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free); 
 therm_mem->SetThreshold(0.5, 0.75);
 
-lab_cpu = new PILabel(statcont, "cpulab", msx-2*(bss+20), 20, 2*bss+20, 60);
+lab_cpu = new PILabel(statcont, "cpulab", msx-2*(bss+20), 20, 2*bss+20, 50);
 lab_cpu->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free); 
 lab_cpu->SetLabel("CPUUsage");
 lab_cpu->SetForegroundColor(PI_Black);
 lab_cpu->SetBorderWidth(1);
-therm_cpu = new PIThermometer(statcont, "cputherm", msx-2*(bss+20), 20, 2*bss+20, 85);
+therm_cpu = new PIThermometer(statcont, "cputherm", msx-2*(bss+20), 15, 2*bss+20, 75);
 therm_cpu->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free); 
 therm_cpu->SetThreshold(0.75, 0.90);
-
- fg_exc_cmd = false;
+lab_thrcmd = new PILabel(statcont, "thrcmdlab", msx-2*(bss+20), 20, 2*bss+20, 95);
+lab_thrcmd->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free); 
+lab_thrcmd->SetLabel("CommandThread");
+lab_thrcmd->SetForegroundColor(PI_Green);
+lab_thrcmd->SetBorderWidth(1);
+
+fg_exc_cmd = false;
+mCmd = NULL;  // Avant d'appeler UpdateStatResource() si PIACmd non cree
 UpdateStatResourceInfo();
 resupd_periodic = new SIA_RU__Periodic(this);
@@ -347,4 +353,5 @@
 delete lab_cpu;
 delete therm_cpu;
+delete lab_thrcmd;
 
 delete statcont;
@@ -372,4 +379,31 @@
 
 }  
+
+/* --Methode-- */
+void PIStdImgApp::Run()
+{
+XEvent evt;
+int szx, szy, szf;
+XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
+// Pour appeler FinishCreate() des objets dans la fenetre principale 
+if (mStop) { // C'est la premiere fois
+  topcont->SetSize(topcont->XSize(), topcont->YSize());
+  MBCont()->FinishCreate();   
+  }
+else mStop = true;   // On rerentre apres un stop 
+
+mCmd->start();
+
+while (mStop) {
+  thr_glsyn.lock(); //  <ZThread> 
+  if (XtAppPending(*appctx) != 0) {
+    XtAppNextEvent(*appctx, &evt);
+    XtDispatchEvent(&evt);
+  }
+  thr_glsyn.unlock(); // <ZThread>
+  usleep(1000);
+}
+return;
+}
 
 /* --Methode-- */
@@ -479,5 +513,6 @@
 #else
   try {
-    mCmd->Interpret(s);
+    //    mCmd->Interpret(s);
+    mCmd->AddInputLine(s);
     }  
   catch ( PThrowable & exc ) {
@@ -559,4 +594,7 @@
 // Pas de same ou inset pour DispImage
 if ((dwopt == Disp_Same) || (dwopt == Disp_Inset) ) dwopt = Disp_Next;
+
+// <ZThread> global PIApplication event loop synchronisation
+ZSync zs(thr_glsyn);  
 
 // Choix de la taille de fenetre
@@ -626,4 +664,8 @@
 DispWinEnum dwopt = ParseDisplayOption(sop, opts);
 if ( (!mLastWdg) && ( (dwopt == Disp_Same) || (dwopt == Disp_Inset) ) )  dwopt = Disp_Next;
+
+// <ZThread> global PIApplication event loop synchronisation
+ZSync zs(thr_glsyn);  
+
 // Trace en superpoistion
 if ( (dwopt == Disp_Same) && (mLastWdg) ) {  
@@ -726,4 +768,8 @@
 
 if ( (!mLastWdg) && ( (dwopt == Disp_Same) || (dwopt == Disp_Inset) ) )  dwopt = Disp_Next;
+
+// <ZThread> global PIApplication event loop synchronisation
+ZSync zs(thr_glsyn);  
+
 // Trace en superpoistion
 if ( (dwopt == Disp_Same) && (mLastWdg) ) {
@@ -1359,4 +1405,19 @@
   else 
     therm_cpu->SetValue(resusg.getAverageCPULoad());
+  int nlx = 0;
+  bool fgx = false;
+  if (mCmd) fgx = mCmd->isRunning(nlx);
+  if (!fgx) {
+    lab = "PIACmdThread Idle";
+    lab_thrcmd->SetLabel(lab);
+    lab_thrcmd->SetForegroundColor(PI_Green);
+  }
+  else {
+    sprintf(buff, "PIACmdThread Running - NL=%d" , nlx);
+    lab = buff;
+    lab_thrcmd->SetLabel(lab);
+    if (nlx < 3)     lab_thrcmd->SetForegroundColor(PI_Yellow);
+    else     lab_thrcmd->SetForegroundColor(PI_Red);   
+  }
 }
 
Index: trunk/SophyaPI/PIext/pistdimgapp.h
===================================================================
--- trunk/SophyaPI/PIext/pistdimgapp.h	(revision 2474)
+++ trunk/SophyaPI/PIext/pistdimgapp.h	(revision 2486)
@@ -34,4 +34,5 @@
 #include "pitherm.h"
 
+#include "zthread.h"
 #include "resusage.h"
 
@@ -53,4 +54,10 @@
      virtual void   SetBlocked();
 
+  // <ZThread>  Multithread execution 
+  // On redefinit la methode Run pour gestion multithread
+     virtual void   Run();
+     inline ZMutex &   getMutex() { return thr_glsyn; }
+
+  // Methodes d'Affichage generique
      int  DispImage(P2DArrayAdapter* nouv, string const & name, string const & opt, int oid=0);
      int  DispScDrawer(PIDrawer* scd, string const & name, string const & opt, 
@@ -171,9 +178,10 @@
     PIPixmap* gimv;
     PICMapView* cmapv;
-  // Pour afficher des stats
+  // Pour afficher des stats et etat thread command
     PILabel* lab_mem;
     PIThermometer* therm_mem;
     PILabel* lab_cpu;
     PIThermometer* therm_cpu;
+    PILabel* lab_thrcmd;
 
     PIFileChooser * pfc_fits;   // Pour les fichiers FITS
@@ -224,4 +232,6 @@
     string exc_command;
     bool fg_exc_cmd;
+  // Attributs pour controle de thread
+    ZMutex thr_glsyn;
 };
 
