thread-to-port assignment

Hi,

I have a question about thread-to-port assignment. There are m threads (they are launched by the same dispatch and share the same queue).
I have two options to create port:

(1) All threads share the same port.

(2) Create one port for each of these m threads. I means we will have m ports.

So, which is better?

Thanks.

hua

[348 byte] By [yuanhp] at [2008-2-7]
# 1
To make it clear:

I have M tasks and launch M threads.
(1)
I can post M task message using only one port.

Or
(2) I can create one port for each of the M tasks (which means M port). Then I post the M task message using M port seperately.

So, which one is better?

yuanhp at 2007-10-2 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Concurrency and Coordination Runtime (CCR)...
# 2

Hi, ports are independent of dispatcher and dispatcher queues. You specify which dispatcher queue you want to use, when you activate, for example

Code Snippet

Arbiter.Activate(

dispatcherQueue,

Arbiter.Receive(true,myPort,myHandler)

);

There is no reason to create a port per task, that would be expensive, if all the tasks call the same handler. Instead use a persisted receiver, use a single port, a single dispatcher queue, and all your tasks will execute as a result from posting messages on that port.

If you want to have fair scheduling between different types of tasks, then create a different dispatcherQueue, per type of task, still use the same dispatcher. When you acttivate your different receivers, on two different ports, use a different dispatcherQueue for each. This makes the CCR round-robin between dispatcher queues, making sure you dont starve one type of tasks.

In the example below, i do use two different ports, and two different dispatcher queues, to illustrate that if you have two different types of tasks to executem and you want to have fair scheduling between them, you need two different dispatcher queues.

Code Snippet

Dispatcher myDispatcher(0,"dispatcher");

DispatcherQueue dqForQueries = new DispatcherQueue(dispatcher,"query queue");

DispatcherQueue dqForUpdates = new DispatcherQueue(dispatcher,"update queue");

Arbiter.Activate(

dqForQueries,

Arbiter.Receive(true,queryPort, QueryHandler)

);

Arbiter.Activate(

dqForUpdates,

Ariter.Receive(true,updatePort, UpdateHandler)

);

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

Microsoft Robotics Studio

Site Classified