Nested Interleaves

Hi!

Is it possible to use nested Interleaves? Consider a scenerio where we have a set of mutually independent receiver-sets that can run concurrently, but individual receivers in each set require to run exclusively within the set.

For example, receivers A, B, C use part S1 of state and hence require running mutually exclusively. Again, receivers D, E, F run mutually exclusively as they modify part S2 of the system state. However, The sets ABC and DEF can run mutually concurrent as they deal with different parts of state. Again, for receivers that work simultaneously with both parts of the state may run exclusively against these sets.

I have found a lot of need for this pattern in complex orchestration programs, but I'm not sure if such a pattern would work.

Piyoosh

[1044 byte] By [Piyoosh] at [2008-2-12]
# 1

YOu can do what you want by using two independent interleaves, then using a special Update message, that is dealt by handler that is in both interleaves. That special Update modifies state that both sets of interleaves need to be exclusive with. This update handler is effectively now running exclusively to both sets of interleaves

this gives you maximum concurrency, and keeps things compositional (the interleaves dont know about each other and just submit a message when they want to update state that affects everyone)

g

GeorgeChrysanthakopoulos at 2007-10-2 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Concurrency and Coordination Runtime (CCR)...
# 2
George Chrysanthakopoulos wrote:

YOu can do what you want by using two independent interleaves, then using a special Update message, that is dealt by handler that is in both interleaves. That special Update modifies state that both sets of interleaves need to be exclusive with. This update handler is effectively now running exclusively to both sets of interleaves

this gives you maximum concurrency, and keeps things compositional (the interleaves dont know about each other and just submit a message when they want to update state that affects everyone)

g

Can you give an example of the solution suggested? Does the code below follows the solution suggested (if I understood correctly)? Will the TeardownReceiver receiver tear down both the interleaves?

Code Snippet

Activate(

Arbiter.Interleave(

new TeardownReceiverGroup(

Arbiter.Receive<TeardownMessage>(false, commonPort, teardownhandler)

),

new ExclusiveReceiverGroup(

Arbiter.Receive<ReplaceFull>(true, commonPort, fullstateReplacehandler)
Arbiter.Receive<PartialReplaceType1_1>(true, portsetA, partialReplaceHandler1_1)
Arbiter.Receive<PartialReplaceType1_2>(true, portsetA, partialReplaceHandler1_2)
),

new ConcurrentReceiverGroup()

)

);

Activate(

Arbiter.Interleave(

new TeardownReceiverGroup(

Arbiter.Receive<TeardownMessage>(false, commonPort, teardownhandler)

),

new ExclusiveReceiverGroup(

Arbiter.Receive<ReplaceFull>(true, commonPort, fullstateReplacehandler)

Arbiter.Receive<PartialReplaceType2_1>(true, portsetB, partialReplaceHandler2_1)
Arbiter.Receive<PartialReplaceType2_2>(true, portsetB, partialReplaceHandler2_2)
),

new ConcurrentReceiverGroup()

)

);

Is the code above similar to the following (hypothetical) code for the problem specified?

Code Snippet

Activate(

Arbiter.Interleave(

new TeardownReceiverGroup(

Arbiter.Receive<TeardownMessage>(false, commonPort, teardownhandler)

),

new ExclusiveReceiverGroup(

Arbiter.Receive<ReplaceFull>(true, commonPort, fullstateReplacehandler)
),

new ConcurrentReceiverGroup(

Arbiter.Interleave(

new TeardownReceiverGroup(),

new ExclusiveReceiverGroup(

Arbiter.Receive<PartialReplaceType1_1>(true, portsetA, partialReplaceHandler1_1),

Arbiter.Receive<PartialReplaceType1_2>(true, portsetA, partialReplaceHandler1_2)

),

new ConcurrentReceiverGroup()

)

),

Arbiter.Interleave(

new TeardownReceiverGroup(),

new ExclusiveReceiverGroup(

Arbiter.Receive<PartialReplaceType2_1>(true, portsetB, partialReplaceHandler2_1)

Arbiter.Receive<PartialReplaceType2_2>(true, portsetB, partialReplaceHandler2_2)

),

new ConcurrentReceiverGroup()

)

),

)

);

Piyoosh at 2007-10-2 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Concurrency and Coordination Runtime (CCR)...
# 3
I think in the first code snippet the ExclusiveReceiverGroup in the first Arbiter runs concurrently with the ExclusiveReceiverGroup in the second Arbiter. If you can guarantee that these exclusive groups do not modify a shared resource it should work fine. However, here I think we cannot guarantee that for the fullstateReplacehandler. Also when commonPort receives a TeardownMessage, only one of the arbiters is shut down and you cannot determine which one picks the message first.
OmidK.Rad at 2007-10-2 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Concurrency and Coordination Runtime (CCR)...
# 4

This is the right approach, the two side by side interleaves is what you want. Omit brings up one good point about the teardown: When you post a TearDownMessage one of the handlers will fire. But it has an easy workaround. Within your TearDownHandler just post back the TeardownMessage in your teardown post. This way all handlers (it does not matter how many interleaves share this teardown port) will execute and the port will end up with one extra teardown message, which is ok (it will GC anyway)
GeorgeChrysanthakopoulos at 2007-10-2 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Concurrency and Coordination Runtime (CCR)...

Microsoft Robotics Studio

Site Classified