Question: Implement the pseudo code in java and C + + program, explain how the semaphores works in the program Pseudocode: class Teams: team _ name

Implement the pseudo code in java and C++ program, explain how the semaphores works in the program
Pseudocode:
class Teams:
team_name
team_members
score (shared variable)
binary_semaphore
def submit_solution(team_name, solution_file, score):
//Critical Section
wait(binary_semaphore)// Ensure only one team member submits at a time
send_file_to_submission_station(solution_file)
signal(binary_semaphore)
class SubmissionStation:
solution_files
counting_semaphore (initialized to the maximum number of concurrent submissions)
def receive_solution(solution_file):
//Critical Section
wait(counting_semaphore)// Limit concurrent submissions
store_solution(solution_file)
signal(counting_semaphore)
def provide_solutions_to_judges():
for solution_file in solution_files:
send_file_to_judge(solution_file)
class Judges:
counting_semaphore (initialized to the number of judges)
def evaluate_solution(solution_file):
//Critical Section
wait(counting_semaphore)// Limit concurrent evaluations
if solution_correct(solution_file):
scorekeeper.update_score(solution_file.team_name)
signal(counting_semaphore)
class Scorekeeper:
team_scores
counting_semaphore (initialized to the maximum number of concurrent updates)
def update_score(team_name, points):
//Critical Section
wait(counting_semaphore)// Protect score updates
team_scores[team_name]+= points
signal(counting_semaphore)
def get_score(team_name):
return team_scores[team_name]

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!