multithreading - Algorithm to run code with no more than one concurrent thread per unique id -
i have go web application needs execute given section of code in 1 goroutine per unique id. scenario have requests coming various ids represent sort of transaction. subset of operations on these needs guaranteed run "one @ at time" given id (and other competing requests should block until prior 1 working on/for id done). i can think of few ways book keeping seems tricky - need keep global mutex lock access map of concurrent requests happening , use mutex or counter there, , make sure doesn't deadlock, , garbage collect (or reference count) old request entries. can this, sounds error prone. is there pattern or in standard library can used effect in case? didn't see obvious. edit: 1 thing think confusing in explanation above use of word "transaction". in case each of these not need explicit close - it's identifier associate multiple operations with. since don't have explicit "close" or "end" concept these, might rec...