EnanoFurtivo

Productor-Consumidor [con contador]

Nov 30th, 2021 (edited)
750
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //PRODUCTOR//
  2. while (true)
  3. {
  4.     while (count == BUFFER_SIZE) ; //Espera ocupada
  5.     //insertar el item en el buffer//
  6.     ++count;
  7.     buffer[in] = item;
  8.     in = (in + 1) % BUFFER_SIZE;
  9. }
  10.  
  11. //CONSUMIDOR//
  12. while (true)
  13. {
  14.     while (count == 0) ; //Espera ocupada
  15.     //Sacar el item del buffer//
  16.     --count;
  17.     item = buffer[out];
  18.     out = (out + 1) % BUFFER_SIZE;
  19. }
RAW Paste Data