Asynchronous Agents Thread Usage RRS feed

  • Question

  • In Parallel Programming with Visual C++ book by Patterns & Practices, in Asynchronous Agents chapter, it is stated that when using agent class, it requires a dedicated thread for whole lifetime of an agent. Is this correct?

    Why is so, isn't receive operation a cooperative blocking operation???

    Tuesday, April 12, 2011 2:33 PM


  • Well, the right answer is "it depends". 

    It depends on how you design the agent.  In the book, that was necessary for that design. 

    But, I have recently seen a number of agents created where the run() action actually initializes state and puts together the data flow network and then completes.  In that design, a thread is not dedicated for the life of the agent -- but it also means that the agent is market as done() through the dataflow actions of its associated message blocks.

    As a meta-point; what happens when we have cooperative blocking is that the runtime is notified that the "processor" (we call it a virtual processor) is "free" and a thread can be assigned to that processor.  So, if there are no started tasks (aka threads, tasks that were blocked but are now unblocked) waiting for this processor, we will start a pending task on the free processor with a new thread. 

    Receive is a cooperative blocking operation so in a traditional Agent, it will have its own thread but if it is waiting on a receive call it will yield its virtual processor to another task, which may result in another thread starting, but don't pay attention to that new (or re-used) thread -- think in tasks.  When a task blocks, another task will be scheduled to run on the resource released by the first task. 

    I hope that clarifies our resource usage.  I hope you like the book!


    Dana Groff, Senior Program Manager Parallel Computing, Concurrency Runtime
    • Proposed as answer by Dana Groff Tuesday, April 26, 2011 11:36 PM
    • Marked as answer by Dana Groff Tuesday, May 17, 2011 5:19 PM
    Tuesday, April 26, 2011 11:36 PM