Skip to content

Pozolotin Oleg / Lab-1 / Dining Programmers#7

Open
jbisss wants to merge 11 commits intomasterfrom
feature/dining-programmers
Open

Pozolotin Oleg / Lab-1 / Dining Programmers#7
jbisss wants to merge 11 commits intomasterfrom
feature/dining-programmers

Conversation

@jbisss
Copy link

@jbisss jbisss commented Sep 24, 2025

Base implementation of Dining Programmers problem


SharedContext.waiters = new Waiter[waitersAmount];
SharedContext.spoons = new Spoon[spoonsAmount];
SharedContext.waiterBlockingQueue = new ArrayBlockingQueue<>(waitersAmount);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему вы остановили свой выбор на этой структуре? Как у вас обстоят дела с равномерностью накормленности? Чем она обеспечивается?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для официантов эта структура была выбрана по той причине, что в моём понимании она достаточно точно описывает модель поведения официантов - программист "забирает" официанта из очереди, чтобы он принёс ему еду, затем официант опять помещается в очередь, готовый, когда будет его время, опять "сходить" за едой

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Равномерность накормленности никак не регулируется мной, упустил этот момент...


private static final Object waitersLock = new Object();

private static int portionsAmount;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно конечно и через лок, но не быстрее ли будет через атомик?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments