title: Why doesn't Pascal FC want to run this code with monitors?
body: <p>I'm programming concurrency in Pascal-FC using Eclipse Gavab 2.0. I haven't had any problems so far using it, as it always inform me of which the errors are when it's unable to execute a program. 
  I did the producer-consumer problem using semaphores and it worked alright. Now I've done it using a monitor, but when I run it, it launches for a second then stops, and does nothing else. It shows no errors at all, and I can't find anything wrong with the code. Is it a compiler's problem? </p>
  
  <p>Producer-Consumer using semaphores: </p>
  
  <pre><code>   program ProdCons;
  const MAXDATOS = 10;
  
  { Creamos el buffer de comunicación: }
  type tBuffer = record
      datos : array [1..MAXDATOS] of integer;
      posInser, posSacar : integer;
      nProductos, nHuecos, em : semaphore;
  end;
  
  var buffer : tBuffer;
  
  
  { METODOS O PROCEDIMIENTOS: }
  procedure inicializar(var buffer : tBuffer);
  begin
      buffer.posInser := 1;
      buffer.posSacar := 1;
      initial(buffer.nProductos,0);
      initial(buffer.nHuecos,MAXDATOS);
      initial(buffer.em,1);
  end;
  
  procedure insertar(dato : integer; var buffer : tBuffer);
  begin
      wait(buffer.nHuecos); {En num de huecos debe ser &gt;0}
  
      wait(buffer.em);
      buffer.datos[buffer.posInser] := dato;
      writeln('Inserta dato ',dato,' en datos[',buffer.posInser,']');
      buffer.posInser := buffer.posInser MOD MAXDATOS + 1;
      signal(buffer.em);
  
      signal(buffer.nProductos); {Confirmamos que num. productos &gt;0}
  end;
  
  procedure sacar(dato : integer; var buffer : tBuffer);
  begin
      wait(buffer.nProductos); {Esperamos a que num. productos &gt;0}
  
      wait(buffer.em);
      dato:=buffer.datos[buffer.posSacar];
      writeln('Consume dato ',dato,' en datos[',buffer.posSacar,']');
      buffer.posSacar := buffer.posSacar MOD MAXDATOS + 1;
      signal(buffer.em);
  
      signal(buffer.nHuecos);
  end;
  
  { PROCESOS TIPO: }
  process type tProductor(var buffer : tBuffer);
  var dato : integer;
  begin
      repeat
          dato := random(200);
          insertar(dato,buffer);
      forever
  end;
  
  process type tConsumidor(var buffer : tBuffer);
  var dato : integer;
  begin
      repeat
          sacar(dato,buffer);
      forever
  end;
  
  
  
  { Variables: }
  var i : integer;
      prod : array [1..5] of tProductor;
      cons : array [1..3] of tConsumidor;
  
  begin
      inicializar(buffer);
      cobegin
          for i:=1 to 5 do
              prod[i](buffer);
  
          for i:=1 to 3 do
              cons[i](buffer);
      coend;
  end.
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/apxkl.png" rel="nofollow">Producer-Consumer with semaphore's output</a></p>
  
  <p>Producer-Consumer using a monitor: </p>
  
  <pre><code>program ProdConsMONITORES;
  const N = 5;
  
  monitor ProdCons;
  
  export produce, consume;
  
  {Variables}
  var posProd, posCons, cont : integer;
      obj : array [1..N] of integer;
      vacio, lleno : condition;
  
  
  {Procedimientos/metodos}
  procedure produce(dato,i : integer);
  begin
      if cont=N then delay(lleno);
      obj[posProd] := dato;
      writeln('Productor',i,' produce dato ',dato,' en obj[',posProd,']');
      posProd := posProd MOD N + 1;
      cont := cont + 1;
      writeln('       [',cont,' objetos disponibles]');
      resume(vacio);
  end;
  
  procedure consume(j : integer);
  var dato := integer;
  begin
      if cont=0 then delay(vacio);
      dato := obj[posCons];
      writeln('Consumidor',j,' consume dato ',dato,' en obj[',posCons,']');
      posCons := posCons MOD N + 1;
      cont := cont - 1;
      writeln('       [',cont,' objetos disponibles]');
      resume(lleno);
  end;
  
  {Procesos}
  process type Productor(i : integer);
  var dato : integer;
  begin
      dato := random(10);
      ProdCons.produce(dato,i);
  end;
  
  process type Consumidor(j : integer);
  begin
      ProdCons.consume(j);
  end;
  
  {Variables locales}
  var p : array [1..5] of Productor;
  var c : array [1..3] of Consumidor;
  var i,j : integer;
  
  begin
  cont := 0;
  posProd := 1; posCons := 1;
  cobegin
      writeln('hola');
      for i:=1 to 5 do
          p[i](i);
      for j:=1 to 3 do
          c[j](j);
  coend;
  end.
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/5fMxY.png" rel="nofollow">Producer-Consumer with monitor's output</a></p>