putMVar places a value into an MVar. If the MVar is already full, the calling thread blocks until another thread empties it with takeMVar. This thread-safe coordination supports imperative-style mutation within IO. section 8.1.3
A request–response exchange uses putMVar to hand work to another thread:
- The requester puts a request into the request MVar, then takes the result from the response MVar. section 8.1.3
- The responder takes the request, processes it, and puts the result into the response MVar. section 8.1.3
- Every takeMVar should eventually pair with putMVar; branching that skips the write can leave other threads blocked indefinitely. section 8.1.3
Worker response
A worker repeatedly takes a request and publishes the processed value with putMVar response (f a), allowing a separate requester to continue.
