This is a rather unusual model for protecting resources from improper concurrent access. . First, I would consider whether you can translate your use case into an equivalent scenario where you can use simple locks. If you could provide more details on why you need such a blocking scheme, the community might come up with other ideas.
To solve your specific question, nothing in .NET or even Win32 directly supports this blocking model , however you can create it from other primitives. I would look at using a pair of ReaderWriterLockSlim instances to protect each resource. When streams are entered into SegmentA, you get a write lock on A and a write lock on B ... and vice versa for streams included in SegmentB. This will allow multiple threads to be executed in each segment, but not at the same time .
EDIT : Given your answer in the comments on your question, I am more convinced that you need to take a look at using the Reader / Writer lock model. What you search is a way to protect a resource that when “writers” do work (serializing a dictionary), neither readers nor other authors can log in, and when “readers” do work, they don’t block each other, but block all others authors, This is a classic case for read / write locks.
EDIT 2 : now that I have more time, I think it’s worth stopping by one question. The way to think about locks is that they protect data resources (memory, files, etc.), and not areas of code. The fact that we need to identify critical sections of code that only one thread can enter at a time is an implementation detail that cannot be confused with how shared resources are used (and they need to be protected). Your question focuses on how to control which threads can go into which section of the code is redirected incorrectly from the real problem: what data resources are you trying to protect from which changes. As soon as you look at a problem from this point of view, it makes it clear which implementation paradigms make sense.
Here are some good resources for read / write lock models:
http://msdn.microsoft.com/en-us/magazine/cc163599.aspx
http://msdn.microsoft.com/en-us/library/bz6sth95.aspx
http://blogs.msdn.com/b/vancem/archive/2006/03/29/564854.aspx
source share