Question: Threads and Deadlock Rationale: To show that threads can be tricky - deadlock states are highly possible. Lab Problem: The code below attempts to implement

Threads and Deadlock

Threads and Deadlock Rationale: To show that threads can be tricky -deadlock states are highly possible. Lab Problem: The code below attempts to

Rationale: To show that threads can be tricky - deadlock states are highly possible. Lab Problem: The code below attempts to implement an authentication protocol between two objects, called Boy and Gir1. The protocol is asynchronous and works as follows: each "pings" the other; when the other is pinged, it responds with a "confirm". When the code is executed the following is output: Starting...1 Girl (ping): pinging Boy Boy (ping): pinging Girl due to a deadlock condition: both Boy and Girl are made to wait in ping and no one can invoke confirm. You may have to run the code several times before you see this. Rework the code to get output that has both the girl and the boy getting confirmation an example looks like this: Starting...1 Girl (ping): pinging Boy Boy (ping): pinging Girl Girl (ping): asking Boy to confirm Boy (confirm): confirm to Girl Girl (ping): got confirmation Boy (ping): asking Girl to confirm Girl (confirm): confirm to Boy Boy (ping): got confirmation The girl and the boy must get confirmation on every run. Try not to blow this off by serializing the code (for example, do not have the Girl autheticate the Boy then have the Boy authenticate the Girl). Leave the ping and the confirm methods in the Monitor (although one or both may be modified by you) and do not change the Runner class except, maybe, to add a print statement or two. Important: the synchronized modifiers before void in ping and confirm in the code below prevent threads from executing inside both ping and confirm concurrently. Your solution must support this property

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!