コード例 #1
0
 @Override
 public Message get(_Consommateur arg0) throws Exception, InterruptedException {
   Message m;
   consoLibre.p(); // on verifie la presence de ressources
   mutex.p(); // acce unique au buffer
   m = msg[debut];
   obs.retraitMessage(arg0, m);
   obstest.retraitMessage(arg0, m);
   debut = (debut + 1) % taille();
   cpt--;
   if (affichage == 1) {
     System.out.println("\tRecuperation IDCons " + arg0.identification() + " : " + m);
   }
   mutex.v(); // deblocage de l'acce au buffer
   prodLibre.v(); // pour avertir les producteurs
   return m;
 }
コード例 #2
0
 @Override
 public void put(_Producteur arg0, Message arg1) throws Exception, InterruptedException {
   prodLibre.p();
   mutex.p(); // blocage du buffer
   msg[fin] = arg1;
   obs.depotMessage(arg0, arg1);
   obstest.depotMessage(arg0, arg1);
   fin = (fin + 1) % taille();
   cpt++;
   if (!(((Producteur) arg0).check())) {
     TestProdCons.producteurAlive--;
     if (affichage == 1) {
       System.out.println("producteurAlive : " + TestProdCons.producteurAlive);
     }
   }
   if (affichage == 1) {
     System.out.println("\tDepot : " + arg1);
   }
   mutex.v(); // deblocage du buffer
   consoLibre.v(); // pour avertir les consommateurs
 }
コード例 #3
0
ファイル: ThreadTP6.java プロジェクト: HKervadec/tp4info
 public void run() {
   System.out.println("Coucou " + this.getName());
   try {
     sem.p();
     Thread.sleep(2000);
     System.out.println("Je suis dans la zone protégé " + this.getName());
     sem.v();
   } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   System.out.println("je suis sorti ! " + this.getName());
 }