❔ Concurrent-exclusive scheduling with prioritizing exclusive execution
First off: I'm aware of
ConcurrentExclusiveSchedulerPair
from TPL, sadly it's not applicable for us, because it doesn't have the scheduling behavior we need.
We have a bunch of messages coming in a sequential channel, that we are processing. Some messages are marked as EXCLUSIVE, some are not. EXCLUSIVE messages must be processed exclusively, as in no other message processing can be done in parallel. If there are only non-exclusive messages to process, the processing of those can happen in parallel. Whenever an exclusive message comes in, no further messages can be processed (except the ones that are already started), this means that if a non-exclusive message slips in after, the processing of that can not be started (this is the major behavior difference we need from ConcurrentExclusiveSchedulerPair
).
Anyone knows of such a scheduler/mechanism implementation somewhere? I'm not too well-versed with parallel/scheduling code so if I don't have to, I wouldn't spend ages trying to make an efficient and decent impl for it.6 Replies
lock statement - synchronize thread access to a shared resource
Use the C# lock statement to ensure that only a single thread exclusively reads or writes a shared resource, blocking all other threads until it completes.
"Whenever an exclusive message comes in, no further messages can be processed", use a lock and a list to store all the non-exclusive ones.
You could combine that with https://learn.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentqueue-1?view=net-7.0
ConcurrentQueue Class (System.Collections.Concurrent)
Represents a thread-safe first in-first out (FIFO) collection.
Uhh... I'll wait for TPL experts to answer 😅
👍
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.