You are given two exclusive resources (targets) labeled "A" and "B".
You need to start N = 10 parallel workers (e.g., processes or threads), each of which performs:
setup()
(may take variable time)
run(target)
where
target
must be either
"A"
or
"B"
The functions below must be treated as black boxes and must not be modified:
def setup():
# DO NOT TOUCH
...
def run(target):
# DO NOT TOUCH
...
run("A")
.
run("B")
.
run(...)
, and a target is free, some worker should run on that target (i.e., don’t unnecessarily serialize all work on a single target).
run(target)
raises or the worker exits unexpectedly (i.e., resources must not be permanently lost).
Implement the worker logic and any required shared synchronization so that starting 10 parallel copies of main() will satisfy the requirements. You may assume Python and typical concurrency primitives (e.g., locks, semaphores, queues), and you may structure the driver code that spawns the 10 workers.