I would like to ask some suggestions to solve this particular deadlock:
3 operators, each is given 2 of 3 different materials at random: 1, 2, 3
3 tools, each material needs a different tool to process by an operator.
material 1 needs tool 1
material 2 needs tool 2
material 3 needs tool 3
Each operator needs to wait for the proper tools to process the materials.
i.e. If an operator has taken material 1,2, he needs tool 1,2
A deadlock may happen:
operator 1 has taken material 1,2, waiting for tool 1,2
operator 2 has taken material 2,3, waiting for tool 2,3
operator 3 has taken material 3,1, waiting for tool 3,1
None of the operator can acquire both tools, what should the operator do?
Proposal
Create a global variable to record the recent 6 materials taken by the operators. If each material appeared twice (example [1,3,1,2,2,3]), then the last operator should keep abandoning the last material until no all materials appear twice (example [1,3,1,2,2,1])?
Will this work? what if I have 10 operators with 3 tools and 3 materials. Any suggestion will help.