Uber Ride Problem
Explore how to implement synchronization in Ruby by solving the Uber Ride Problem, ensuring safe multi-threaded interactions between Democrat and Republican rider threads. Understand the use of mutexes, semaphores, and barriers to coordinate thread seating and ride initiation, modeling real-world concurrency challenges.
We'll cover the following...
Uber Ride Problem
Imagine at the end of a political conference, republicans and democrats are trying to leave the venue and ordering Uber rides at the same time. However, to make sure no fight breaks out in an Uber ride, the software developers at Uber come up with an algorithm whereby either an Uber ride can have all democrats or republicans or two Democrats and two Republicans. All other combinations can result in a fist-fight.
Your task as the Uber developer is to model the ride requestors as threads. Once an acceptable combination of riders is ...