Index: /trunk/SophyaProg/Tests/zthr.cc
===================================================================
--- /trunk/SophyaProg/Tests/zthr.cc	(revision 3184)
+++ /trunk/SophyaProg/Tests/zthr.cc	(revision 3185)
@@ -31,6 +31,6 @@
 // --- Structure d'argument pour fonction d'execution dans les threads de test
 typedef struct  {
-  int_4 thid;
-  int_4 M;
+  int_4 thid, NTh;
+  int_4 M, VSz;
 } ztarg;
 
@@ -120,7 +120,47 @@
   ~MTVecPool()   { }
   // Renvoie un pointeur de vecteur pour thread tid
-  TVector<int_8>*  GetVec(uint_4 tid, uint_4& idx)
-  {
-    if (tid >= _nth) ParmError("MTVecPool::getvec() tid > _nth");
+  TVector<int_8>*  GetVecP(uint_4 tid, uint_4& idx)
+  {
+    if (tid >= _nth) ParmError("MTVecPool::GetVecP() tid > _nth");
+    //DBG  cout << "DBG-GetVecP(tid= " << tid << ")" << endl;
+    if (tid == 0) {
+      mex.lock();
+      St_VecPool stv;
+      idx = _vecs.size();
+      stv.vv = _vmx.Column(idx);
+      stv.busy = true;
+      stv.stat = 0;
+      _vecs.push_back(stv);
+      mex.unlock();
+      //DBG cout << "DBG-GetVecP(tid= " << tid << ") -> Idx=" << idx << " VecSz=" << &(_vecs[idx].vv) << endl;
+      return (&(_vecs[idx].vv));
+    }
+    else {
+      mex.lock();
+      bool found = false;
+      while (!found) {
+	for(uint_4 k=0; k<_vecs.size(); k++) {
+	  if ( (_vecs[k].stat == tid) && (! _vecs[k].busy) ) {
+	    found = true;  idx = k;
+	    _vecs[k].stat = tid; _vecs[k].busy = true; 
+	    break;
+	  }
+	}
+	if (found) {
+	  mex.unlock();
+	  //DBG  cout << "DBG-GetVecP(tid= " << tid << ") -> nv=" << hex << rv << dec << endl;
+	  return (&(_vecs[idx].vv));
+	}
+	else { 
+	  mex.broadcast();
+	  mex.wait();
+	}
+      }
+    }
+  }
+  // Renvoie un vecteur pour thread tid
+  TVector<int_8>  GetVec(uint_4 tid, uint_4& idx)
+  {
+    if (tid >= _nth) ParmError("MTVecPool::GetVec() tid > _nth");
     //DBG  cout << "DBG-GetVec(tid= " << tid << ")" << endl;
     if (tid == 0) {
@@ -134,5 +174,5 @@
       mex.unlock();
       //DBG cout << "DBG-GetVec(tid= " << tid << ") -> Idx=" << idx << " VecSz=" << &(_vecs[idx].vv) << endl;
-      return (&(_vecs[idx].vv));
+      return (_vecs[idx].vv);
     }
     else {
@@ -150,5 +190,5 @@
 	  mex.unlock();
 	  //DBG  cout << "DBG-GetVec(tid= " << tid << ") -> nv=" << hex << rv << dec << endl;
-	  return (&(_vecs[idx].vv));
+	  return (_vecs[idx].vv);
 	}
 	else { 
@@ -207,4 +247,33 @@
 static MTVecPool* mtvp = NULL;
 
+// --- fonction de test avec synchronisation entre threads en utilisant pointeur de vecteurs
+void syncp_funzt(void *arg)
+{
+  ztarg * za = (ztarg *)arg;
+  cout << ">>>> syncp_funzt(ThId=" << za->thid << ") - NVec/NLoop= " << za->M << endl;
+  
+  if (mtvp == NULL) 
+    throw NullPtrError("syncp_funzt: MTVecPool* mtvp = NULL");
+
+  int_4 L = za->M;
+  int_4 VS = za->VSz;
+  int_8 p2 = 1;
+  uint_4 k, ii, tid;
+  tid = za->thid;
+  for(k=0; k<tid; k++) p2 *= 2;
+
+  char buff[128];
+  sprintf(buff, "syncp_funzt(ThId=%d) StarOfLoop", za->thid); 
+  PrtTim(buff);
+  uint_4 idx;
+  for(k=0; k<L; k++) {
+    *(mtvp->GetVecP(tid, idx)) += p2;
+    //DBG cout << "DBG-syncp_funzt(tid=" << tid << ", idx=" << idx << endl;
+      mtvp->RetVec(idx);
+  }
+  sprintf(buff, "syncp_funzt(ThId=%d) EndOfLoop", za->thid); 
+  PrtTim(buff);
+  return;
+}
 // --- fonction de test avec synchronisation entre threads
 void sync_funzt(void *arg)
@@ -217,6 +286,7 @@
 
   int_4 L = za->M;
+  int_4 VS = za->VSz;
   int_8 p2 = 1;
-  uint_4 k, tid;
+  uint_4 k, ii, tid;
   tid = za->thid;
   for(k=0; k<tid; k++) p2 *= 2;
@@ -227,5 +297,5 @@
   uint_4 idx;
   for(k=0; k<L; k++) {
-    *(mtvp->GetVec(tid, idx)) += p2;
+    mtvp->GetVec(tid, idx) += p2;
     //DBG cout << "DBG-sync_funzt(tid=" << tid << ", idx=" << idx << endl;
     mtvp->RetVec(idx);
@@ -247,5 +317,5 @@
 static int N = 1;
 static int M = 5;
-static int VSZ = 128;
+static int VSZ = 32;
 
 int main(int narg, char *arg[])
@@ -260,7 +330,8 @@
     cout << "  select= clk -> Mutex lock count  " << endl;
     cout << "  select= sync -> Thread synchronisation using ZMutex" << endl;
+    cout << "  select= syncp -> Thread synchronisation using ZMutex , Vector pointers" << endl;
     cout << "  N= Number of threads (sl/mtx) or CountLock " << endl;
     cout << "  LM = Loop limit (sl/sync) or Matrix size (mtx) " << endl;
-    cout << "  Sz = Vector size for select=sync (default=256) " << endl;
+    cout << "  Sz = Vector size for select=sync,syncp (default=32) " << endl;
     return(1);
   }
@@ -268,5 +339,5 @@
   string sel = arg[1];
   if ((sel != "sl") && (sel != "mtx") && (sel != "arr") && 
-      (sel != "sync") && (sel != "clk")) {
+      (sel != "sync") && (sel != "syncp") && (sel != "clk")) {
     cout << "zthr/erreur argument sel (!= sl / mtx / arr / clk) " << endl;
     return 2;
@@ -287,6 +358,6 @@
   try {
     ResourceUsage res(ResourceUsage::RU_All);
-    if ((sel == "mtx") || (sel == "arr") || (sel == "sl") || (sel == "sync") ) {
-      if (sel == "sync") mtvp = new MTVecPool(N,VSZ,M);
+    if ((sel == "mtx") || (sel == "arr") || (sel == "sl") || (sel == "sync") || (sel == "syncp")) {
+      if ( (sel == "sync") || (sel == "syncp"))  mtvp = new MTVecPool(N,VSZ,M);
       vector<ztarg *> vza;
       vector<ZThread *> vzth;
@@ -298,8 +369,10 @@
 	// ATTENTION : il faut que le thid = 0 ... N-1 (et pas 1)
 	zap->thid = i;  zap->M = M;
+	zap->NTh = N;   zap->VSz = VSZ;
 	vza.push_back(zap);
 	if (sel == "mtx")  pzt->setAction(mtx_funzt, vza[i]);
 	else if (sel == "arr")  pzt->setAction(arr_funzt, vza[i]);
 	else if (sel == "sync")  pzt->setAction(sync_funzt, vza[i]);
+	else if (sel == "syncp")  pzt->setAction(syncp_funzt, vza[i]);
 	else pzt->setAction(funzt, vza[i]);
       }
@@ -313,7 +386,7 @@
       for(int i=0; i<N; i++) vzth[i]->join();
       cout << "***zthr Threads Z1 ... Z" << N << " Finished OK" << endl;
+      cout << " zthr/Resusage: getDataSize() = " << res.getDataSize() << "  getStackSize()=" 
+	   << res.getStackSize() << endl;
       cout << res;
-      cout << " Resu: getDataSize() = " << res.getDataSize() << "  getStackSize()=" 
-	   << res.getStackSize() << endl;
       for(int i=0; i<N; i++) {
 	delete vzth[i];
