Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "metadata": {
- "trusted": true
- },
- "cell_type": "code",
- "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",
- "execution_count": null,
- "outputs": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "name": "java",
- "display_name": "Java",
- "language": "java"
- },
- "toc": {
- "nav_menu": {},
- "number_sections": false,
- "sideBar": false,
- "skip_h1_title": false,
- "base_numbering": 1,
- "title_cell": "Table of Contents",
- "title_sidebar": "Contents",
- "toc_cell": false,
- "toc_position": {},
- "toc_section_display": false,
- "toc_window_display": false
- },
- "language_info": {
- "nbconverter_exporter": "",
- "codemirror_mode": "text/x-java",
- "name": "Java",
- "mimetype": "",
- "file_extension": ".java",
- "version": "1.8.0_152-release"
- },
- "widgets": {
- "application/vnd.jupyter.widget-state+json": {
- "version_major": 2,
- "version_minor": 0,
- "state": {}
- }
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Add Comment
Please, Sign In to add comment