C
C#9mo ago
Knikedix

multi threaded gate lock OR

Using the Monitor class, is there a way to create a lock with n input values, which creates a lock for each value? First thought was to create the locks in a loop and map the objects to a key. This will potentionally lead to desdlocks so its not an option.
3 Replies
Cracker
Cracker9mo ago
what does create a lock with n input values mean ? Iterate over some items and lets say for each 10 items you want to process some action in thread safe way (with use of lock) ?
mtreit
mtreit9mo ago
You might want to describe your exact scenario, but if you want a lock that lets n threads through (to throttle too many things happening at once for instance) you want a semaphore.
Knikedix
KnikedixOP9mo ago
I realize I was quite vague, I’ll witte up a method to explain it a bit more in detail later. Made an implementation with the SemaphoreSlim class. Worked wonders together with an ephemeron to keep track of the ones currently in need. @mtreit Thanks a lot for the suggestion!
Want results from more Discord servers?
Add your server