Throtting constraints

I think my understanding of throtting constraints is broken. I assumed the following code would

only print "3" and "c", but it prints all values posted to both ports.

Code Snippet

using (Dispatcher dispatcher =newDispatcher())

{

DispatcherQueue dq =newDispatcherQueue(

"Test",

dispatcher,

TaskExecutionPolicy.ConstrainQueueDepthDiscardTasks,

1);

Port<int> intPort =newPort<int>();

Port<string> stringPort =newPort<string>();

Port<Shutdown> endPort =newPort<Shutdown>();

intPort.Post(1);

intPort.Post(2);

intPort.Post(3);

stringPort.Post("a");

stringPort.Post("b");

stringPort.Post("c");

Arbiter.Activate(dq,Arbiter.Interleave(

newTeardownReceiverGroup(

Arbiter.Receive(false, endPort,delegate(Shutdown s)

{

})),

newExclusiveReceiverGroup(

Arbiter.Receive(true, intPort,delegate(int i)

{

Thread.Sleep(1000);

Console.WriteLine(i.ToString());

}),

Arbiter.Receive(true, stringPort,delegate(string s)

{

Thread.Sleep(1000);

Console.WriteLine(s);

})),

newConcurrentReceiverGroup()));

Console.ReadLine();

endPort.Post(newShutdown());

}

Would someone tell me why this behaves the way it does?

The Thread.Sleep() call is there to simulate a consumer much slower than its producer...

[4899 byte] By [NickGunn] at [2008-2-4]
# 1
Sorry forgot to say, this is based on the 1.5 May CTP.
NickGunn at 2007-9-28 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Concurrency and Coordination Runtime (CCR)...
# 2

Hi Nick, the Interleave arbiter does not throttle, it instead manages concurrency. It "interleaves" execution between all handlers based on constraints.

All values you posted will be printed because the interleave will make sure all the tasks run at some point. But it also makes sure that when your exclusive handler is sleeping/busy, no concurrent handler or any other exclusive handler, runs at the same time.

GeorgeChrysanthakopoulos at 2007-9-28 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Concurrency and Coordination Runtime (CCR)...

Microsoft Robotics Studio

Site Classified