quiz حل الأسئلة الجامعية manage_search الأرشيف

تم الحل ✓
categoryعلوم الحاسوب وتقنية المعلومات schoolبكالوريوس event_available2026-07-14

السؤال

Transcribed Image Text:

Problem: Consider a system with three smoker processes and one agent process (multiple threads problem). Each smoker continuously rolls a cigarette and then smokes it. But to roll and smoke a cigarette, the smoker needs three ingredients: tobacco, paper, and matches. One of the smoker processes has paper, another has tobacco, and the third has matches. The agent has an infinite supply of all three materials. Every time the agent places two of the ingredients on the table. The smoker who has the remaining ingredient then makes and smokes a cigarette, signaling the agent on completion. The agent then puts out another two of the three ingredients, and the cycle repeats. Write a program to synchronize the agent and the smokers using Java synchronization. Requirements: • One class for Smoker that you should create 3 threads, and one class for agent that you have one thread. . You should show that your solution works by having each smoker thread smoke three cigarettes at least. • Print out the result for some long period and analysis your result. • Finally you need to analysis to see if deadlock occurs? If yes, under what condition?

check_circle الجواب — حل مفصل خطوة بخطوة

hourglass_top