Algorithme de Dekker

Description du code

Code source ou contenu du fichier

  1. PROCEDURE dekker_s_algorithm IS
  2. TYPE process_enumeration IS(first,second);
  3. favored_process : process_enumeration;
  4. p1_wants_to_enter,
  5. p2_wants_to_enter : boolean;
  6.  
  7. PROCEDURE process_one IS
  8. BEGIN
  9. LOOP
  10. p1_wants_to_enter := true;
  11. WHILE p2_wants_to_enter LOOP
  12. IF favored_process = second THEN
  13. p1_wants_to_enter := false;
  14. WHILE favored_process = second LOOP
  15. NULL;
  16. END LOOP;
  17. p1_wants_to_enter := true;
  18. END IF;
  19. END LOOP;
  20. critical_section_one;
  21. favored_process := second;
  22. p1_wants_to_enter := false;
  23. other_stuff_one;
  24. END LOOP;
  25. END process_one;
  26. PROCEDURE process_two IS
  27. BEGIN
  28. LOOP
  29. p2_wants_to_enter := true;
  30. WHILE p1_wants_to_enter LOOP
  31. IF favored_process = first THEN
  32. p2_wants_to_enter := false;
  33. WHILE favored_process = first LOOP
  34. NULL;
  35. END LOOP;
  36. p2_wants_to_enter := true;
  37. END IF;
  38. END LOOP;
  39. critical_section_two;
  40. favored_process := first;
  41. p2_wants_to_enter := false;
  42. other_stuff_two;
  43. END LOOP;
  44. END process_two;
  45.  
  46. BEGIN
  47. p1_wants_to_enter := false;
  48. p2_wants_to_enter := false;
  49. favored_process := first;
  50. PARBEGIN
  51. process_one;
  52. process_two;
  53. PAREND;
  54. END dekker_s_algorithm;

Autres extraits de codes en ada

Document créé le 05/10/2009, dernière modification le 28/10/2018
Source du document imprimé : https://www.gaudry.be/sniplet-rf-ada/dekker_s_algorithm.ada.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.