Guest User

Untitled

a guest
Jan 22nd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "metadata": {
  5. "trusted": true
  6. },
  7. "cell_type": "code",
  8. "source": "class DinningPhilosophers {\n \n final int N = 5;\n \n Fork[] forks = new Fork[N];\n Philosopher[] philosophers = new Philosopher[N];\n \n boolean semaphors = new semaphors[5]\n \n void eat() {\n // eat\n }\n \n void thinking(){\n // think\n }\n \n \n takeFork(int index) {\n // take fork\n }\n \n \n void solution() {\n \n while (true) {\n thinking();\n takeFork(i);\n takeFork((i+1)%N);\n eat();\n putFork(i)\n putFork((i+1)%N);\n }\n }\n \n void solutionWithSemaphore(semaphores s[]) {\n while (true) {\n thinking();\n wait(takeFork(s[i]));\n wait(takeFork(s[(i+1)%N])); \n eat();\n notify(putFork(i));\n notify(putFork((i+1)%N));\n }\n }\n }\n}\n",
  9. "execution_count": null,
  10. "outputs": []
  11. }
  12. ],
  13. "metadata": {
  14. "kernelspec": {
  15. "name": "java",
  16. "display_name": "Java",
  17. "language": "java"
  18. },
  19. "toc": {
  20. "nav_menu": {},
  21. "number_sections": false,
  22. "sideBar": false,
  23. "skip_h1_title": false,
  24. "base_numbering": 1,
  25. "title_cell": "Table of Contents",
  26. "title_sidebar": "Contents",
  27. "toc_cell": false,
  28. "toc_position": {},
  29. "toc_section_display": false,
  30. "toc_window_display": false
  31. },
  32. "language_info": {
  33. "nbconverter_exporter": "",
  34. "codemirror_mode": "text/x-java",
  35. "name": "Java",
  36. "mimetype": "",
  37. "file_extension": ".java",
  38. "version": "1.8.0_152-release"
  39. },
  40. "widgets": {
  41. "application/vnd.jupyter.widget-state+json": {
  42. "version_major": 2,
  43. "version_minor": 0,
  44. "state": {}
  45. }
  46. }
  47. },
  48. "nbformat": 4,
  49. "nbformat_minor": 2
  50. }
Add Comment
Please, Sign In to add comment