Advertisement
Guest User

filosofo1.adb

a guest
Nov 12th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. with Ada.Text_IO; use Ada.Text_IO;
  2.  
  3. procedure Filosofo1 is
  4.  
  5. type izq is range 0 .. 4;
  6. task Comedor is
  7. entry ENTRAR;
  8. entry SALIR;
  9. end Comedor;
  10. task body Comedor is
  11.  
  12. begin
  13. cant := izq'First;
  14. loop
  15. select
  16. when cant < 5 =>
  17. accept ENTRAR;
  18. cant := cant + 1;
  19. or
  20. accept SALIR;
  21. cant := cant - 1;
  22. end select;
  23. end loop;
  24. end Comedor;
  25.  
  26. task Numerador is
  27. entry dmn(x:integer);
  28. end Numerador;
  29. task body Numerador is
  30. i: integer;
  31. begin
  32. for i in izq loop
  33. accept dmn(n : out int) do
  34. n := i;
  35. end dmn;
  36. end loop;
  37. end Numerador;
  38.  
  39. task type Palito is
  40. entry Pedir;
  41. entry Devolver;
  42. end Palito;
  43. task body Palito is
  44. begin
  45. loop
  46. accept Pedir;
  47. accept Devolver;
  48. end loop;
  49. end Palito;
  50.  
  51. Palitos : array (izq) of Palito;
  52.  
  53. task type Filosofo is
  54.  
  55. end Filosofo;
  56. task body Filosofo is
  57. izquierda: izq;
  58. der : izq;
  59. c:Comedor;
  60.  
  61. begin
  62.  
  63. numerador.dmn(izq);
  64. der:=(izq+1)mod 5;
  65.  
  66. loop
  67. Put_Line ("El filosofo" & izq'Image(i) & " esta pensando");
  68. c.ENTRAR;
  69. Palitos(izq).Pedir;
  70. Palitos(der).Pedir;
  71. Put_Line ("El filosofo" & izq'Image(i) & " esta comiendo");
  72. Palitos(der).Devolver;
  73. Palitos(izq).Devolver;
  74. c.SALIR;
  75. end loop ;
  76. end FILOSOFO ;
  77. Filosofos: array (izq) of Filosofo;
  78.  
  79.  
  80. begin
  81. Put_Line ("Comienza simulador");
  82. end Filosofo1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement