<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Parallel Programming in Native Code : Asynchronous Agents</title><link>http://blogs.msdn.com/nativeconcurrency/archive/tags/Asynchronous+Agents/default.aspx</link><description>Tags: Asynchronous Agents</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Writing a Custom Message Block – Part 1: Introduction</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/12/15/writing-a-custom-message-block-part-1-introduction.aspx</link><pubDate>Tue, 15 Dec 2009 00:14:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9936822</guid><dc:creator>Mike Chu</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9936822.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9936822</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9936822</wfw:comment><description>&lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/dd504833(VS.100).aspx"&gt;Asynchronous Agents Library&lt;/a&gt; within the Concurrency Runtime provides a set of basic message blocks which can be used to create a message passing network. In most cases, these blocks have sufficient enough flexibility and can be composed together to provide all the necessary functionality for your message-passing network. However, there are cases in which the provided blocks do not have the exact behavior you want, and a custom message block is desired. In this post, I will discuss the process for creating your own custom message block.&lt;/p&gt;  &lt;h4&gt;What kind of message block are you writing?&lt;/h4&gt;  &lt;p&gt;The first thing to decide when creating a message block is to determine what &lt;i&gt;kind&lt;/i&gt; if block you desire. Is it a &lt;b&gt;source&lt;/b&gt; block, in which case it only offers messages but does not receive them, or is it a &lt;b&gt;target&lt;/b&gt; block, which can only receive messages for processing, but does not offer them out to anyone else? It could also be a combination of the two, a block that both receives from sources and offers to targets. &lt;/p&gt;  &lt;p&gt;The Asynchronous Agents Library contains two interfaces &lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd470870(VS.100).aspx"&gt;ISource&lt;/a&gt;&lt;/b&gt; and &lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd492505(VS.100).aspx"&gt;ITarget&lt;/a&gt;&lt;/b&gt;, which provides the API interface for source and target blocks, respectively. While you are free to create your own block from these interfaces, we highly recommend you use one of the three base classes we provide: &lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd492847(VS.100).aspx"&gt;source_block&lt;/a&gt;&lt;/b&gt;, &lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd492402(VS.100).aspx"&gt;target_block&lt;/a&gt;&lt;/b&gt;, and &lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd504864(VS.100).aspx"&gt;propagator_block&lt;/a&gt;&lt;/b&gt;. These are explained in the table below:&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="1" width="521"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="150"&gt;         &lt;p&gt;&lt;b&gt;source_block&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="369"&gt;         &lt;p&gt;A block that is only a source of messages. This block offers messages to other blocks, but cannot receive messages.&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="153"&gt;         &lt;p&gt;&lt;b&gt;target_block&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="366"&gt;         &lt;p&gt;A block that is only a target of messages. This block receives messages from other blocks, but cannot offer them.&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="156"&gt;         &lt;p&gt;&lt;b&gt;propagator_block&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="364"&gt;         &lt;p&gt;A block that is both a source and target of messages. This block can both receive messages from a source and propagate message out to other blocks.&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;We recommend using these base classes because they significantly ease the process of developing a custom message block. They take care of all the error checking, safe unlinking and the required locks so they free you up to focus purely on the desired behavior of your message block.&lt;/p&gt;  &lt;p&gt;All three base classes are templated on their network link registry type. This defines how many source or target links a block can have. The Asynchronous Agents Library contains two such link registries: &lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd470440(VS.100).aspx"&gt;single_link_registry&lt;/a&gt;&lt;/b&gt; and &lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd470717(VS.100).aspx"&gt;multi_link_registry&lt;/a&gt;&lt;/b&gt;, which allow a single or multiple links, respectively. For example, if you wanted to create a message block that was purely a source block and can only accept one target, you would declare your message block as:&lt;/p&gt;  &lt;p align="center"&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;class&lt;/font&gt; example : &lt;font color="#0000ff"&gt;public&lt;/font&gt; source_block&amp;lt;single_link_registry&amp;lt;ITarget&amp;lt;_Type&amp;gt;&amp;gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Similarly, you could specify the block to use &lt;b&gt;multi_link_registry&lt;/b&gt; to allow multiple links. This is only differentiated because a &lt;b&gt;single_link_registry&lt;/b&gt; can be slightly optimized over multiple links.&lt;/p&gt;  &lt;p&gt;I will now focus on creating source and target blocks, and how they can be customized for different behavior. A propagator block would have the combination of the two.&lt;/p&gt;  &lt;h4&gt;Writing a source_block&lt;/h4&gt;  &lt;p&gt;A &lt;b&gt;source_block&lt;/b&gt; is a block that offers messages to its targets. Thus, it must deal with target blocks calling back to it to take messages. The following six methods must be defined in your derived class and can be customized to change the behavior of your block:&lt;/p&gt;  &lt;p&gt;   &lt;table border="1" cellspacing="0" cellpadding="1" width="535"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="533"&gt;           &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;virtual void&lt;/font&gt; propagate_to_any_targets(message&amp;lt;_Type&amp;gt; * _PMessage)&lt;/font&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="533"&gt;           &lt;p&gt;This method is the main propagation routine for a &lt;b&gt;source_block&lt;/b&gt;. This is where your block should be processing the received message and offering messages to its targets. This method is called automatically when calling one of two methods: &lt;b&gt;async_send&lt;/b&gt; or &lt;b&gt;sync_send&lt;/b&gt;, which are used to asynchronously or synchronously propagate a message out, respectively. These two methods are present on every block and serve to initiate either a asynchronous or synchronous propagation for the block.&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;   &lt;table border="1" cellspacing="0" cellpadding="1" width="535"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="533"&gt;           &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;virtual&lt;/font&gt; message&amp;lt;_Type&amp;gt; * accept_message(runtime_object_identity _MsgId)&lt;/font&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="533"&gt;           &lt;p&gt;This method is called from a target block after they are offered a message from this &lt;b&gt;source_block&lt;/b&gt;. The call to &lt;b&gt;accept &lt;/b&gt;must be made within the source’s call to &lt;b&gt;target::propagate&lt;/b&gt;, thus this is part of the message passing handshake. The method is used to take ownership of the offered message. A common issue to decide in&lt;b&gt; accept_message&lt;/b&gt; is if your block returns the actual offered message itself, or copies of messages. For example, our &lt;b&gt;unbounded_buffer&lt;/b&gt; block passes the specific message offered to its targets, and only one will receive that message. Our &lt;b&gt;overwrite_buffer&lt;/b&gt;, on the other hand, returns copies to each of its targets, so all targets can get a version of the message.&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;   &lt;table border="1" cellspacing="0" cellpadding="1" width="535"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="533"&gt;           &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;virtual bool&lt;/font&gt; reserve_message(runtime_object_identity _MsgId)&lt;/font&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="533"&gt;           &lt;p&gt;This method is called from a target block after they are offered a message from this &lt;b&gt;source_block&lt;/b&gt; and want to reserve the message to consume it later. The function should return true if you want to allow this message to be reserved, false otherwise.&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;   &lt;table border="1" cellspacing="0" cellpadding="1" width="535"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="533"&gt;           &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;virtual&lt;/font&gt; message&amp;lt;_Type&amp;gt; * consume_message(runtime_object_identity _MsgId)&lt;/font&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="533"&gt;           &lt;p&gt;This method is called from a target block after they have already successfully reserved a message and now wish to consume it. Similar to &lt;b&gt;accept&lt;/b&gt;, a common issue to decide here is whether to return the specific message or a copy of the message.&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;   &lt;table border="1" cellspacing="0" cellpadding="1" width="535"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="533"&gt;           &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;virtual void&lt;/font&gt; release_message(runtime_object_identity _MsgId)&lt;/font&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="533"&gt;           &lt;p&gt;This method is called from a target block after they have already successfully reserved a message and now do not wish to consume it. Mostly cleanup and possibly error checking should be done here.&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;   &lt;table border="1" cellspacing="0" cellpadding="1" width="535"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="533"&gt;           &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;virtual void&lt;/font&gt; resume_propagation()&lt;/font&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="533"&gt;           &lt;p&gt;This method is automatically called when a reserved message is consumed or a message is released. Here, you should decide how to proceed with propagation. In general an &lt;b&gt;async_send(NULL)&lt;/b&gt; should be called, which will simply force the block to restart propagation without a new message.&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;h4&gt;Writing a target_block&lt;/h4&gt;  &lt;p&gt;A &lt;b&gt;target_block&lt;/b&gt; is a block that can accept messages offered from its sources. Thus, it must deal with messages being passed to it from sources. There are two methods than can be overridden to handle the messages, &lt;b&gt;propagate_message&lt;/b&gt; and &lt;b&gt;send_message&lt;/b&gt;. Only &lt;b&gt;propagate_message&lt;/b&gt; must be overridden in the derived class; send defaults to not allowing synchronous propagation.&lt;/p&gt;  &lt;p&gt;   &lt;table border="1" cellspacing="0" cellpadding="1" width="535"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="533"&gt;           &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;virtual&lt;/font&gt; message_status propagate_message(message&amp;lt;_Type&amp;gt; * _PMessage,                 &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ISource&amp;lt;_Type&amp;gt; * _PSource)&lt;/font&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="533"&gt;           &lt;p&gt;This method is called after a message, &lt;b&gt;_PMessage&lt;/b&gt;, has been &lt;i&gt;asynchronously&lt;/i&gt; offered from source &lt;b&gt;_PSource &lt;/b&gt;and has successfully passed any filter that you may have added to your block. The message has not yet been accepted, so ownership still resides with the source &lt;b&gt;_PSource&lt;/b&gt;. Thus, this &lt;b&gt;target_block&lt;/b&gt; can now be customized to do whatever it wants with the message and source. Typically, you want to call               &lt;br /&gt;&lt;b&gt;_PSource-&amp;gt;accept(_PMessage-&amp;gt;msg_id(), this);                &lt;br /&gt;&lt;/b&gt;&lt;/p&gt;            &lt;p&gt;in order to take ownership of this message from the source. However, the implementation of this method is totally dependent on the desired behavior for this block.&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;   &lt;table border="1" cellspacing="0" cellpadding="1" width="535"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="533"&gt;           &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;virtual&lt;/font&gt; message_status send_message(message&amp;lt;_Type&amp;gt; * _PMessage,                 &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ISource&amp;lt;_Type&amp;gt; * _PSource)&lt;/font&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="533"&gt;           &lt;p&gt;This method is exactly the same as propagate_message except that the message&lt;b&gt; _PMessage&lt;/b&gt; has been&lt;i&gt; synchronously&lt;/i&gt; offered from source &lt;b&gt;_PSource &lt;/b&gt;.&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;h4&gt;Combining the two: Writing a propagator_block&lt;/h4&gt;  &lt;p&gt;The main usage of a &lt;b&gt;propagator_block&lt;/b&gt; is its ability to receive a message, like a &lt;b&gt;target_block&lt;/b&gt;, then manipulate that message and send it out, like a &lt;b&gt;source_block&lt;/b&gt;. Thus, creating a &lt;b&gt;propagator_block&lt;/b&gt; is simply the combination of the methods defined above. The propagation of a received message can be done by using either of the two methods&lt;b&gt;: async_send &lt;/b&gt;and &lt;b&gt;sync_send&lt;/b&gt;. &lt;/p&gt;  &lt;p&gt;The &lt;b&gt;async_send(message * _PMessage)&lt;/b&gt; method will spin up a light-weight task in the Concurrency Runtime which will asynchronously call &lt;b&gt;propagate_to_any_targets(_PMessage)&lt;/b&gt; to manipulate the messages as you wish according to your custom block, and offer the message out to its targets.&lt;/p&gt;  &lt;p&gt;Similarly, the &lt;b&gt;sync_send(message * _PMessage)&lt;/b&gt; method will also offer the message out to its targets, but does so synchronously, in line.&lt;b&gt; &lt;/b&gt;&lt;/p&gt;  &lt;h4&gt;Example: Squaring block&lt;/h4&gt;  &lt;p&gt;As a simple example, let’s look at how I would write a simple message block that accepts any message from a source, squares the received message payload, then propagates out a message with the square to its targets.&lt;/p&gt;  &lt;p&gt;First, since this block both receives in and sends out messages, I need to make it a &lt;b&gt;propagator_block&lt;/b&gt;. I’ll define the class as:     &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160;&amp;#160; template&lt;/font&gt;&amp;lt;&lt;font color="#0000ff"&gt;class&lt;/font&gt; _Type = &lt;font color="#0000ff"&gt;int&lt;/font&gt;&amp;gt;       &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160;&amp;#160; class&lt;/font&gt; squaring_block :&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt; propagator_block&amp;lt;multi_link_registry&amp;lt;ITarget&amp;lt;_Type&amp;gt;&amp;gt;,&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;multi_link_registry&amp;lt;ISource&amp;lt;_Type&amp;gt;&amp;gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This class declaration specifies that my block is a &lt;b&gt;propagator_block&lt;/b&gt; that can link to any number of targets and be linked from any number of sources.&lt;/p&gt;  &lt;p&gt;Next, I’ll need some place to store my messages as they arrive in this block. I’ll need to store them in case, for example, the input throughput exceeds the output throughput, or in case a target reserves one of the offered messages and we need to stall the network pipeline until it is consumed or released. To do this, let’s just include a simple queue that holds our messages:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; std::queue&amp;lt;message&amp;lt;_Type&amp;gt; *&amp;gt; messageBuffer;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Depending on your block, you may not need to store a queue of messages, or any messages at all. It all depends on the functionality you desire.&lt;/p&gt;  &lt;p&gt;First, I’ll specify the constructor and destructor for the block:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; squaring_block()      &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; {&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;initialize_source_and_target();      &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; ~squaring_block()      &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; remove_network_links();      &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The call to &lt;b&gt;initialize_source_and_target&lt;/b&gt; is a base class method for &lt;b&gt;propagator_block &lt;/b&gt;that initializes the block and allows you to specify which &lt;b&gt;Scheduler&lt;/b&gt; or &lt;b&gt;ScheduleGroup&lt;/b&gt; this block uses. For simplicity, and in most cases, we can just call this method with no arguments. (The &lt;b&gt;source_block &lt;/b&gt;and &lt;b&gt;target_block&lt;/b&gt; base classes have &lt;b&gt;initialize_source &lt;/b&gt;and &lt;b&gt;initialize_target&lt;/b&gt; methods, respectively.) The destructor must call &lt;b&gt;remove_network_links&lt;/b&gt;, which is another base class method. This method is critical in that it ensures the links to and from this block are properly removed before destructing the object. Otherwise, asynchronous propagations could be continuing to deleted memory.&lt;/p&gt;  &lt;p&gt;Now, let’s move on to the interesting aspects about customizing the block. As a target, this &lt;b&gt;squaring_block&lt;/b&gt; is going to receive messages offered to it. A source block will do this by calling &lt;b&gt;squaring_block::propagate&lt;/b&gt;. Since we are deriving from &lt;b&gt;propagator_block&lt;/b&gt;, all the necessary error handling has already been done, and we just need to specify what happens after we get a message that we actually want in the &lt;b&gt;propagate_message&lt;/b&gt; function (which is called by &lt;b&gt;propagate&lt;/b&gt;):&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160;&amp;#160; virtual&lt;/font&gt; message_status propagate_message(message&amp;lt;_Type&amp;gt; * _PMessage,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;ISource&amp;lt;_Type&amp;gt; * _PSource)&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;{&amp;#160; &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; message_status result = accepted;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _PMessage = _PSource-&amp;gt;accept(_PMessage-&amp;gt;msg_id(), this);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if&lt;/font&gt; (_PMessage != NULL)&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;{&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;async_send(_PMessage);&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;}&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font color="#0000ff" face="Consolas"&gt;else&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;{&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;result = missed;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;return&lt;/font&gt; result;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The code here simply tries to accept a message from the source by calling&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;b&gt;_PSource-&amp;gt;accept&lt;/b&gt;, then, if it properly returned a message, it would call &lt;b&gt;async_send(_PMessage)&lt;/b&gt; on the returned message. As soon as the &lt;b&gt;accept &lt;/b&gt;call has returned, the message has transferred ownership to our &lt;b&gt;squaring_block&lt;/b&gt; from the source; however, our &lt;b&gt;squaring_block&lt;/b&gt; has not yet processed or stored away the message and prepared it for transferring to any of our targets. That process is initiated by &lt;b&gt;async_send&lt;/b&gt;.&lt;/p&gt;  &lt;p&gt;Similar to &lt;b&gt;propagate_message&lt;/b&gt;, there is a &lt;b&gt;send_message&lt;/b&gt; function which can be specified. This function happens on a synchronous path, while propagate is for the asynchronous. For this purposes of this block, we only need to change the implementation to call &lt;b&gt;sync_send&lt;/b&gt; instead of &lt;b&gt;async_send&lt;/b&gt; and everything else is the same.&lt;/p&gt;  &lt;h4&gt;Propagation of messages&lt;/h4&gt;  &lt;p&gt;Now how about processing and offering the message out to the &lt;b&gt;squaring_block&lt;/b&gt;’s targets? This is done via the source methods that were outlined earlier. First, let’s specify the &lt;b&gt;propagate_to_any_targets&lt;/b&gt; method. This is the method that is called in a light-weight task created by the call to &lt;b&gt;async_send&lt;/b&gt; during &lt;b&gt;propagate_message &lt;/b&gt;and is where all the main processing should occur.&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;virtual void&lt;/font&gt; propagate_to_any_targets(message&amp;lt;_Type&amp;gt; * _PMessage)&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;if&lt;/font&gt; (_PMessage != NULL)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font color="#008000"&gt;// Square the input, delete the original message&lt;/font&gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;_Type outputPayload = _PMessage-&amp;gt;payload * _PMessage-&amp;gt;payload;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;message&amp;lt;_Type&amp;gt; * newMessage = new message&amp;lt;_Type&amp;gt;(outputPayload);      &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;delete&lt;/font&gt; _PMessage;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; messageQueue.push(newMessage);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;if&lt;/font&gt; (messageQueue.size() &amp;gt; 1)&amp;#160; &lt;br /&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt;;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;while&lt;/font&gt; (messageQueue.size() &amp;gt; 0)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;message_status status = declined;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;for&lt;/font&gt; (target_iterator _Iter = _M_connectedTargets.begin();       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;*_Iter != NULL; ++_Iter)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;{&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;ITarget&amp;lt;_Target_type&amp;gt; * _PTarget = *_Iter;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; s&lt;/font&gt;&lt;font face="Consolas"&gt;tatus = _PTarget-&amp;gt;propagate(messageQueue.front(), this);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#008000"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font face="Consolas"&gt;// Ownership of message changed. Do not propagate this&lt;/font&gt;         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // message to any other target.&lt;/font&gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;if&lt;/font&gt; (status == accepted)&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;break&lt;/font&gt;;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#008000" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // If status is anything other than accepted, then the current &lt;/font&gt;&lt;font face="Consolas"&gt;     &lt;br /&gt;&lt;font color="#008000"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // message was not propagated out. Nothing after it can be        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // propagated out.&lt;/font&gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;if&lt;/font&gt; (status != accepted)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;break&lt;/font&gt;;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;}&amp;#160; &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Let’s step through that code slowly and investigate how I made this block behave how I wanted it to. The first part of the function is focused on the processing of the message:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font color="#008000"&gt;// Square the input, delete the original message&lt;/font&gt;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;_Type outputPayload = _PMessage-&amp;gt;payload * _PMessage-&amp;gt;payload;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;message&amp;lt;_Type&amp;gt; * newMessage = new message&amp;lt;_Type&amp;gt;(outputPayload);&amp;#160; &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;delete&lt;/font&gt; _PMessage;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; messageQueue.push(newMessage);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;if&lt;/font&gt; (messageQueue.size() &amp;gt; 1)       &lt;br /&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt;; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;First, upon receiving a message I squared the input, providing the desired functionality of this block. Next, I delete the old message, since this &lt;b&gt;squaring_block&lt;/b&gt; is the current owner of it, but its lifetime will end with this block; i.e. there will be no further propagations of that specific message out of this block. Then, I checked if there was any current message being offered by this block. If so, I enqueue the new message to the queue of stored messages and return; otherwise, I can begin propagation.&lt;/p&gt;  &lt;p&gt;One subtle note about message processing: while I technically could have done the processing of the message by squaring the input in &lt;b&gt;propagate_message&lt;/b&gt; rather than in &lt;b&gt;propagate_to_any_targets&lt;/b&gt;, it is better practice to do the latter. This is because &lt;b&gt;propagate_message&lt;/b&gt; is called from your block’s source, thus it is running in a task initiated by your source. Doing processing in &lt;b&gt;propagate_to_any_targets&lt;/b&gt; is better because it is your block’s propagation task.&lt;/p&gt;  &lt;p&gt;At this point, everything else in the &lt;b&gt;propagate_to_any_targets&lt;/b&gt; method has to do with the actual propagation to targets. The message has already been processed and is ready for offering. The main &lt;b&gt;while&lt;/b&gt; loop takes each message, one at a time starting with the head, and offers it to each of the targets, also one at a time. By using our standard &lt;b&gt;multi_link_registry&lt;/b&gt; and our base classes, I’m able to use our included iterators to search through the targets with a simple for loop and propagate out to my targets:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;for&lt;/font&gt; (target_iterator _Iter = _M_connectedTargets.begin();&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;*_Iter != NULL; ++_Iter)&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;ITarget&amp;lt;_Target_type&amp;gt; * _PTarget = *_Iter;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; s&lt;/font&gt;&lt;font face="Consolas"&gt;tatus = _PTarget-&amp;gt;propagate(messageQueue.front(), this);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#008000"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font face="Consolas"&gt;// Ownership of message changed. Do not propagate this&lt;/font&gt;         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // message to any other target.&lt;/font&gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;if&lt;/font&gt; (status == accepted)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;break&lt;/font&gt;;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This takes the currentMessage and propagates it out to the targets. After each propagate call returns, we check to see what the result is. If it was accepted, that means the ownership has changed and we can break out and offer the next message in our queue. Otherwise, we should propagate it to the next target we have. If no target accepts the message, we propagation should stall until that currentMessage is accepted or consumed. We cannot propagate other messages in the queue, otherwise messages will be propagated out of order.&lt;/p&gt;  &lt;p&gt;Now that we’ve created a block that can offer messages out, we need to handle what happens when a target block calls back and tries to take the offered message. This is handled in the &lt;b&gt;accept_message&lt;/b&gt; method:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160;&amp;#160; virtual&lt;/font&gt; message&amp;lt;_Type&amp;gt; * accept_message(runtime_object_identity _MsgId)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;message&amp;lt;_Type&amp;gt; * msg = NULL;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;if&lt;/font&gt; (messageQueue.front()-&amp;gt;msg_id() == _MsgId)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;msg = messageQueue.front();      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;messageQueue.pop();      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;}&lt;/font&gt;&lt;font face="Consolas"&gt;      &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt; msg;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This method just checks to see if the message the target is trying accept is the same as the current one that my &lt;b&gt;squaring_block&lt;/b&gt; is holding and trying to propagate. If so, it dequeues it from my block, and returns it to the target. &lt;b&gt;Note&lt;/b&gt;: as soon as it returns the message, ownership of the message has changed hands. We can no longer safely touch that message pointer.&lt;/p&gt;  &lt;p&gt;At this point, we have a block that can participate in both &lt;i&gt;synchronous&lt;/i&gt; and &lt;i&gt;asynchronous&lt;/i&gt; message passing! For completeness, there are four more functions to handle reserving and consuming of messages. However, as this post is long enough already, I’ll simplify this block by disallowing reserving and consuming of message. In my next post, I’ll dive into the details of how to handle proper reserving of messages. Disallowing reservations can be done by:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;virtual&lt;/font&gt; &lt;font color="#0000ff"&gt;bool&lt;/font&gt; reserve_message(runtime_object_identity _MsgId)       &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;return&lt;/font&gt; false;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;virtual&lt;/font&gt; message&amp;lt;_Type&amp;gt;* consume_message(runtime_object_identity _MsgId)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt; NULL;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;virtual void&lt;/font&gt; release_message(runtime_object_identity _MsgId)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;virtual void&lt;/font&gt; resume_propagation()       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Consolas"&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;So that’s it! That’s a rather lengthy, but in-depth introduction to writing custom message blocks! Please let me know if there’s anything still confusing or there’s any interesting custom message blocks that you come up with! Look for my next post soon on allowing reservations.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9936822" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/concurrency/default.aspx">concurrency</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Concurrency+Runtime/default.aspx">Concurrency Runtime</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Asynchronous+Agents/default.aspx">Asynchronous Agents</category></item><item><title>Code Samples for the Concurrency Runtime, Agents Library and Parallel Pattern  Library updated for Beta2</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/11/12/code-samples-for-the-concurrency-runtime-agents-library-and-parallel-pattern-library-updated-for-beta2.aspx</link><pubDate>Thu, 12 Nov 2009 14:25:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9921349</guid><dc:creator>rickmolloy</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9921349.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9921349</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9921349</wfw:comment><description>&lt;p&gt;We’ve posted an update to our sample pack at &lt;a href="http://code.msdn.com/concrtextras"&gt;http://code.msdn.com/concrtextras&lt;/a&gt; for Visual Studio 2010 Beta2 . The newest thing is this drop of the sample pack are the three new header files in the ConcRTExtras folder.&amp;#160; Here’s what these files contain:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;ppl_extras.h &lt;/strong&gt;contains additional stl style parallel algorithms like parallel_accumulate, parallel_partial_sum, parallel_transform, parallel_all_of, parallel_any_of, parallel_none_of and also parallel_for_fixed, parallel_accumulate_fixed, parallel_partial_sum_fixed.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;agents_extras.h &lt;/strong&gt;contains additional useful message blocks like spriority_buffer, bounded_buffer, alternator, join_transform and&amp;#160; a recalculate_buffer.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;concrt_extras.h &lt;/strong&gt;contains useful wrapper classes and functions from the runtime itself like concrt_suballocator a std::allocator built on &lt;a href="http://msdn.microsoft.com/en-us/library/dd492420(VS.100).aspx"&gt;Concurrency::Alloc&lt;/a&gt;, task_scheduler, schedule_group and schedule_task which are simple wrapper classes around &lt;a href="http://msdn.microsoft.com/en-us/library/dd492385(VS.100).aspx"&gt;Scheduler&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/dd504865(VS.100).aspx"&gt;ScheduleGroup&lt;/a&gt; that offer functor support like PPL for scheduling tasks.&lt;/p&gt;  &lt;p&gt;These are located in the Concurrency::samples namespace and the team will be blogging about many of these over the coming weeks, but please feel free to ask any questions here or in the &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/parallelcppnative/threads"&gt;forums&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;-Rick&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9921349" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/concurrency/default.aspx">concurrency</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Asynchronous+Agents/default.aspx">Asynchronous Agents</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_0x/default.aspx">C++0x</category></item><item><title>What’s new in Beta 2 for the Concurrency Runtime, Parallel Pattern Library and Asynchronous Agents Library</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/10/29/what-s-new-in-beta-2-for-the-concurrency-runtime-parallel-pattern-library-and-asynchronous-agents-library.aspx</link><pubDate>Thu, 29 Oct 2009 17:05:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9914817</guid><dc:creator>rickmolloy</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9914817.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9914817</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9914817</wfw:comment><description>&lt;p&gt;Last week Visual Studio 2010 Beta was released &lt;a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx"&gt;for download&lt;/a&gt;. Since Beta1, the team has been pretty busy adding enhanced functionality to make you more productive at expressing parallelism in your applications and improving the quality and performance of our runtime and programming models.&lt;/p&gt;  &lt;p&gt;Here’s a guide to what’s new in Beta2: we’ve added 2 new concurrent containers, significantly enhanced our online documentation and improved our debug experience by adding better visualizations and more intuitive views in the parallel debug window. We’ve also modified a small number of APIs which you should be aware of if you are using Beta 1. &lt;/p&gt;  &lt;h4&gt;Concurrent containers – concurrent_queue and concurrent_vector&lt;/h4&gt;  &lt;p&gt;We’ve alluded more than once to concurrent_queue and concurrent_vector in our videos and live talks, these are finally in the box and with them two new header files concurrent_queue.h and concurrent_vector.h.&lt;/p&gt;  &lt;p&gt;concurrent_queue&amp;lt;T&amp;gt; is very similar to std::queue&amp;lt;T&amp;gt; and it offers push, try_pop interfaces and ‘unsafe’ iterators and size accessors (these aren’t threadsafe during concurrent pushes and pops). &lt;/p&gt;  &lt;p&gt;concurrent_vector&amp;lt;T&amp;gt; is most similar to a std::vector&amp;lt;T&amp;gt; and it offers a push_back method that is internally synchronized across threads and allows efficient thread safe growth of the vector. Like std::vector, concurrent_vector has random access iterators, but unlike std::vector, the guarantee of contiguous storage is removed and there are no insert and erase methods.&lt;/p&gt;  &lt;p&gt;The interfaces to concurrent_queue and concurrent_vector will be incredibly familiar if you are a user of Intel’s Threading Building Blocks (the interfaces are identical), and a very big thank you goes out to their team for their assistance with this.&lt;/p&gt;  &lt;p&gt;Here’s a brief example that uses both std::queue and std::vector in a parallel loop: &lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #cc6633"&gt;#include&lt;/span&gt; &amp;lt;ppl.h&amp;gt;&lt;br /&gt;&lt;span style="color: #cc6633"&gt;#include&lt;/span&gt; &amp;lt;concurrent_vector.h&amp;gt;&lt;br /&gt;&lt;span style="color: #cc6633"&gt;#include&lt;/span&gt; &amp;lt;concurrent_queue.h&amp;gt;&lt;br /&gt;&lt;span style="color: #cc6633"&gt;#include&lt;/span&gt; &amp;lt;iostream&amp;gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; Concurrency;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; std;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; main()&lt;br /&gt;{&lt;br /&gt;    concurrent_vector&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; odds;&lt;br /&gt;    concurrent_queue&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; evens;&lt;br /&gt;    parallel_for(0,100,1,[&amp;amp;odds,&amp;amp;evens](&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i){&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (i%2 == 0)&lt;br /&gt;            evens.push(i);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;br /&gt;            odds.push_back(i);&lt;br /&gt;    }); &lt;br /&gt;    cout &amp;lt;&amp;lt; &lt;span style="color: #006080"&gt;&amp;quot;We expect 100 items: &amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; evens.unsafe_size() + odds.size() &amp;lt;&amp;lt; endl;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;h5&gt;Debugging enhancements in Beta2&lt;/h5&gt;

&lt;p&gt;VS 2010 Beta 2 also now includes significant enhancements for parallel debugging. The locals window now includes visualizers for all first class objects in the PPL, the Agents Library so now when you a look at an instance of a concurrent_queue or an ubounded_buffer in the locals window they both look a lot like a std::queue instead of exposing implementation details. The &lt;a href="http://channel9.msdn.com/posts/DanielMoth/Parallel-Tasks--new-Visual-Studio-2010-debugger-window/"&gt;Parallel Tasks&lt;/a&gt; and &lt;a href="http://channel9.msdn.com/posts/DanielMoth/Parallel-Stacks--new-Visual-Studio-2010-debugger-window/"&gt;Parallel Stacks&lt;/a&gt; windows have also been enhanced; in addition to those videos, try the &lt;a href="http://msdn.microsoft.com/en-us/library/dd554943(VS.100).aspx"&gt;C++ code in the MSDN walkthrough&lt;/a&gt; and &lt;a href="http://www.danielmoth.com/Blog/"&gt;Daniel Moth’s blog&lt;/a&gt;. Finally, like the rest of the C Runtime, we’ve made our source code for the Concurrency Runtime available as part of the install, so if you need to debug deeper or really want to see how things work internally, you can now.&lt;/p&gt;

&lt;h5&gt;Documentation updated with more How To’s and walkthroughs&lt;/h5&gt;

&lt;p&gt;Our offline and &lt;a href="http://msdn.microsoft.com/en-us/library/dd504870(VS.100).aspx"&gt;online documentation&lt;/a&gt; has been significantly updated for Beta2. We’ve added multiple conceptual topics and expanded our How To topics significantly to include information not just on PPL and the Agents Library but on the underlying Concurrency Runtime and how to manage and use &lt;a href="http://msdn.microsoft.com/en-us/library/dd984036(VS.100).aspx"&gt;scheduler instances&lt;/a&gt;. Any feedback on these topics is greatly appreciated.&lt;/p&gt;

&lt;h5&gt;API updates to task_group and agent&lt;/h5&gt;

&lt;p&gt;For Beta 2, we’ve made a very small number of API updates to our task_group, structured_task_group and to our agent classes. The change to the agent is simple describe, we’ve simplified the state management and removed the parameter for the agent::done method, it’s sufficient to call this-&amp;gt;done() instead of this-&amp;gt;done(agent_done).&lt;/p&gt;

&lt;p&gt;The change to task_group and structured_task_group is additive, we’ve added the method run_and_wait which takes a functor and runs it inline on the current thread or task. This offers the major benefit of being able to compose tasks and nest their cancellation. One of the easiest ways to see this in action is through implementing a parallel search algorithm, like a parallel version of the new C++0x library function ‘all_of’:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;template&lt;/span&gt;&amp;lt;&lt;span style="color: #0000ff"&gt;class&lt;/span&gt; InIt,&lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Pr&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;inline&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; parallel_all_of(InIt first, InIt last, Pr pred)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;   &lt;span style="color: #0000ff"&gt;typedef&lt;/span&gt; iterator_traits&amp;lt;InIt&amp;gt;::value_type Item_type;&lt;br /&gt;&lt;br /&gt;   &lt;span style="color: #008000"&gt;//create a structured task group&lt;/span&gt;&lt;br /&gt;   structured_task_group tasks;&lt;br /&gt;&lt;br /&gt;   &lt;span style="color: #0000ff"&gt;auto&lt;/span&gt; for_each_predicate = [&amp;amp;pred,&amp;amp;tasks](&lt;span style="color: #0000ff"&gt;const&lt;/span&gt; Item_type&amp;amp; cur){&lt;br /&gt;&lt;br /&gt;   &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!pred(cur))&lt;br /&gt;      tasks.cancel();&lt;br /&gt;   };&lt;br /&gt;&lt;br /&gt;   &lt;span style="color: #0000ff"&gt;auto&lt;/span&gt; task = make_task([&amp;amp;](){&lt;br /&gt;      parallel_for_each(first,last,for_each_predicate);&lt;br /&gt;   });&lt;br /&gt;&lt;br /&gt;   &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; tasks.run_and_wait(task) != canceled;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Here we are placing a call to parallel_for_each inside of a structured_task_group and cancelling the work when the predicate is not true. This has the effect of cancelling all nested tasks in the structured_task_group, potentially saving work if the predicate is long running and expensive to compute. We can use this in our example above like this (but don’t expect to see significant speedups over std::all_of for this example):&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (parallel_all_of(odds.begin(),odds.end(),[](&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i){&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; i % 2;}))&lt;br /&gt;    cout &amp;lt;&amp;lt; &lt;span style="color: #006080"&gt;&amp;quot;success!&amp;quot;&lt;/span&gt; &amp;lt;&amp;lt; endl;&lt;br /&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h5&gt;So try Beta 2 if you haven’t already&lt;/h5&gt;

&lt;div&gt;That’s about it for now, so &lt;a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx"&gt;download VS 2010 Beta 2&lt;/a&gt; if you haven’t already and if you’re at PDC or TechEd Europe next month stop by our booth or &lt;a href="http://blogs.msdn.com/pfxteam/archive/2009/10/16/9908290.aspx"&gt;come to one our talks&lt;/a&gt;.&lt;/div&gt;

&lt;p&gt;-Rick&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9914817" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Concurrency+Runtime/default.aspx">Concurrency Runtime</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Parallel+Pattern+Library/default.aspx">Parallel Pattern Library</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Asynchronous+Agents/default.aspx">Asynchronous Agents</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/PDC09/default.aspx">PDC09</category></item><item><title>Asynchronous Agents Library - Intro to Message Blocks</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/07/02/asynchronous-agents-library-intro-to-message-blocks.aspx</link><pubDate>Thu, 02 Jul 2009 21:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9814721</guid><dc:creator>Steve Gates</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9814721.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9814721</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9814721</wfw:comment><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;In my previous post I talked about the agent class. Now I will introduce the Agents Library’s &lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd504833(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd504833(VS.100).aspx"&gt;&lt;FONT face=Calibri size=3&gt;message blocks&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt;, how to use them, and the fundamentals of what they do. I will cover some basics that apply to all of the message blocks, introduce the messaging APIs, and then specifically explain three blocks: unbounded_buffer, overwrite_buffer, and single_assignment.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Message Blocks&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;In the Agents Library we have created a set of interfaces and defined a protocol for message blocks to communicate and exchange messages. Message blocks are intended to be used to establish defined communication protocols between isolated components and develop concurrent applications based on data flow. The message blocks provided by the Agents Library can be used in conjunction with the agents class itself or separately.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;For more information on data flow - &lt;/FONT&gt;&lt;A href="http://en.wikipedia.org/wiki/Dataflow" mce_href="http://en.wikipedia.org/wiki/Dataflow"&gt;&lt;FONT face=Calibri size=3&gt;http://en.wikipedia.org/wiki/Dataflow&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;ISource and ITarget Interfaces&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd470870(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd470870(VS.100).aspx"&gt;&lt;FONT face=Calibri size=3&gt;ISource&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; and &lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd492505(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd492505(VS.100).aspx"&gt;&lt;FONT face=Calibri size=3&gt;ITarget&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; are base interfaces message blocks work with. They declare functions for handling linking and exchanging messages. A source block implements ISource, a target block ITarget, and a propagator block, a block that is a source and a target, implements both. In this blog I will only be discussing the functions needed to use the message blocks provided by the Agents Library. A more comprehensive knowledge of the functions in the ISource and ITarget interfaces are required when creating your own message blocks; this will be discussed in a later post.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Linking/Unlinking and Creating Messaging Networks&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Often it is desirable to link message blocks together to create a network. One such reason for building messaging networks is to create data flow pipelines.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The following three functions, declared on the ISource interface, are used to connect source blocks to target blocks:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;void&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt; link_target(ITarget&amp;lt;_Type&amp;gt; * _PTarget);&lt;/SPAN&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt; – adds a link to the specified target. This causes the source block to offer any of its messages to the target until it is unlinked.&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;void&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt; unlink_target(ITarget&amp;lt;_Type&amp;gt; * _PTarget);&lt;/SPAN&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt; – removes an existing link with the specified target, once unlinked no more messages will be presented to the target.&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; unlink_targets();&lt;/SPAN&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt; – removes all links with any target blocks.&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Here is a simple example connecting and then disconnecting two unbounded_buffers:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;unbounded_buffer&amp;lt;&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;&amp;gt; buffer1, buffer2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;buffer1.link_target(&amp;amp;buffer2);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;...&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;buffer2.unlink_target(&amp;amp;buffer2);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Some blocks have restrictions on the number of targets allowed; invalid_link_target exception is thrown in these cases&lt;/FONT&gt;&lt;A style="mso-comment-reference: stg_1; mso-comment-date: 20090617T1752"&gt;&lt;FONT face=Calibri size=3&gt;.&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Basic Message Propagation&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Messages are exchanged between blocks using light weight tasks (LWTs) on a scheduler, because of this message propagation works cooperatively with any other work in the same scheduler. This means long running tasks that never block or yield can slow down or cease the forward progress of message delivery. Thus is the nature of working in a cooperative environment.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;All of the message blocks built into the Agents Library guarantee in-order message delivery. It is possible to create your own blocks which do not preserve order, however all of built in ones do.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd492424(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd492424(VS.100).aspx"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Calibri size=3&gt;Messaging APIs&lt;/FONT&gt;&lt;/B&gt;&lt;/A&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt; - send, asend, receive, and try_receive&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Once creation of messaging networks and propagation of messages is understood the only other thing needed to start programming is how to insert and remove messages directly from individual blocks. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Two global functions are used to create and insert messages:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;bool&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt; send(ITarget&amp;lt;_Type&amp;gt; &amp;amp;_Trg, &lt;SPAN style="COLOR: blue"&gt;const&lt;/SPAN&gt; _Type &amp;amp;_Data);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; asend(ITarget&amp;lt;_Type&amp;gt; &amp;amp;_Trg, &lt;SPAN style="COLOR: blue"&gt;const&lt;/SPAN&gt; _Type &amp;amp;_Data);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Each of these takes a target and the data to transmit. Send synchronously originates a message with a target, whereas asend asynchronously does. This means a send call will block until the target either takes the message or declines it. Send returns true if the message was delivered and false otherwise. Asend will not block until the target takes the message, it offers the message and immediately returns. A return value of true means the target has accepted the message and will eventually take it, otherwise false means the target either declined the message or postponed the decision on whether or not to take it until later. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Likewise here are the two global functions for removing or extracting messages:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;template&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt; &amp;lt;&lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; _Type&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; TEXT-INDENT: -0.5in; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;_Type receive(ISource&amp;lt;_Type&amp;gt; &amp;amp; _Src, &lt;SPAN style="COLOR: blue"&gt;unsigned&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; _Timeout = COOPERATIVE_TIMEOUT_INFINITE);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; TEXT-INDENT: -0.5in; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;template&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt; &amp;lt;&lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; _Type&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; TEXT-INDENT: -0.5in; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;bool&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt; try_receive(ISource&amp;lt;_Type&amp;gt; &amp;amp; _Src, _Type &amp;amp; _value);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Receive takes a source block to extract a message from and an optional timeout, the extracted value is the return value. If a message is currently not available in the source then receive will block until one is, optionally a timeout also may be specified. Correspondingly try_receive will only obtain a message if the source has one at that instance, otherwise it returns immediately. A return value of true on try_receive indicates a message was received, false means one was not.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;All of these functions when blocking do so cooperatively with the Concurrency Runtime. To learn more about working cooperatively with the Concurrency Runtime take a look at the series of posts on &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2009/04/22/synchronization-with-the-concurrency-runtime.aspx" mce_href="http://blogs.msdn.com/nativeconcurrency/archive/2009/04/22/synchronization-with-the-concurrency-runtime.aspx"&gt;&lt;FONT face=Calibri size=3&gt;Synchronization with the Concurrency Runtime&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;unbounded_buffer&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd492602(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd492602(VS.100).aspx"&gt;&lt;FONT face=Calibri size=3&gt;Unbounded_buffer&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; is one of the most basic messaging blocks; it acts very similar to a queue. As its name suggests unbounded_buffer can store any number of messages, limited only by memory, collected from its source links (links to blocks that have the unbounded_buffer as a target). Unbounded_buffer always accepts all messages offered to it. Messages propagated to an unbounded_buffer are collected into a queue and then offered one at a time to each of its targets. Each message in an unbounded_buffer will only be given to one of its targets based on link ordering. This means targets of an unbounded_buffer compete for messages.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Unbounded_buffer provides two utility functions:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;bool&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt; enqueue(_Type &lt;SPAN style="COLOR: blue"&gt;const&lt;/SPAN&gt;&amp;amp; _Item);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;_Type dequeue();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Each of these is equivalent to send and receive respectively, and basically are wrappers around them.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-INDENT: 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;unbounded_buffer&amp;lt;&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;&amp;gt; buffer;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// These are equivalent.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;buffer.enqueue(1);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;send(buffer, 1);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// And so are these.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; value = buffer.dequeue();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; value = receive(buffer);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Unbounded_buffers are excellent for producer/consumer patterns. In a previous post &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2009/06/03/introduction-to-asynchronous-agents-library.aspx" mce_href="http://blogs.msdn.com/nativeconcurrency/archive/2009/06/03/introduction-to-asynchronous-agents-library.aspx"&gt;&lt;FONT face=Calibri size=3&gt;Introduction to Asynchronous Agents Library&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; the FindString agents sample makes use of unbounded_buffers to communicate between the individual agents. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;overwrite_buffer&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Essentially &lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd492533(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd492533(VS.100).aspx"&gt;&lt;FONT face=Calibri size=3&gt;overwrite_buffer&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; is a simple broadcaster. Overwrite_buffer is a message block that holds one message at a time, very similar to a variable. Every time an overwrite_buffer receives a message it offers a copy of it to any of its targets and then stores the message internally, replacing any previously stored message. The important thing to note here is there is no competition for data. Every time a message comes into an overwrite_buffer it is offered to all of its targets, then afterwards it can be overwritten at any point.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Overwrite_buffer also provides two utility functions:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-INDENT: 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;bool&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt; has_value() &lt;SPAN style="COLOR: blue"&gt;const &lt;/SPAN&gt;;&lt;SPAN style="COLOR: blue"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-INDENT: 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;_Type value();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Has_value returns true or false indicating whether or not the overwrite_buffer has received its first message. Value is a wrapper around receive. Has_value can be used to check if overwrite_buffer has a message, if overwrite_buffer does then calling value or receive will not be a blocking call. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Uses of overwrite_buffer include tracking state, continuously monitoring status, or broadcasting messages. In the Agents Library the &lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd551463(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd551463(VS.100).aspx"&gt;&lt;FONT face=Calibri size=3&gt;agent&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; class takes advantage of this using an overwrite_buffer internally to track its state. Calling the start, cancel, done, and wait functions work with agent’s the internal overwrite_buffer.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;single_assignment&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd470880(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd470880(VS.100).aspx"&gt;&lt;FONT face=Calibri size=3&gt;Single_assignment&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; behaves very similar to overwrite_buffer, except it will only accept one message from any of its sources. Once single_assignment accepts a message all subsequent offered messages will be declined. Just like overwrite_buffer, single_assignment gives a copy of the message to each of its targets; there is no competition for data.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Single_assignment provides the following two utility functions:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;bool&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt; has_value() &lt;SPAN style="COLOR: blue"&gt;const &lt;/SPAN&gt;;&lt;SPAN style="COLOR: blue"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;_Type &lt;SPAN style="COLOR: blue"&gt;const&lt;/SPAN&gt; &amp;amp; value();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;These perform exactly same as in overwrite_buffer.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Single_assignments are useful when a single value is read by many, similar to a const variable. A single_assignment can also be used to pick the first available message from a group of blocks. The offered message will be accepted and all others will be declined. Used in this form single_assignment can act as a choice or chooser from a group of blocks.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;In following posts I will introduce more of the message blocks and provide sample applications.&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9814721" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/concurrency/default.aspx">concurrency</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Asynchronous+Agents/default.aspx">Asynchronous Agents</category></item><item><title>Synchronization with the Concurrency Runtime - Part 3</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/06/04/synchronization-with-the-concurrency-runtime-part-3.aspx</link><pubDate>Thu, 04 Jun 2009 23:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9700258</guid><dc:creator>vinodsu</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9700258.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9700258</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9700258</wfw:comment><description>&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;In my previous posts, I addressed the motivation behind using concurrency runtime’s synchronization primitives and also introduced Critical Section and reader writer lock. In this blog, I will cover concurrency runtime’s event.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Event&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-add-space: auto" class=MsoListParagraphCxSpFirst&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;This is a bi-state type class which, unlike Critical Section or Reader Writer Lock, does not protect access to shared data. Events synchronize flow of execution and use concurrency runtime’s facilities to enable cooperative schedule of work. They behave similar to &lt;SPAN class=MsoCommentReference&gt;Win32 &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/ms682655(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms682655(VS.85).aspx"&gt;&lt;SPAN style="LINE-HEIGHT: 115%; mso-bidi-font-size: 8.0pt"&gt;&lt;FONT color=#0000ff size=3 face=Calibri&gt;manual-reset event&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/A&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN class=MsoCommentReference&gt;. The main difference between the concurrency runtime’s event and Win32 event is that the concurrency runtime’s event are designed to cooperatively yield to other cooperative tasks in the runtime when blocked in addition to preempting whereas Win32 events are, by design purely pre-emptive in nature.&lt;/SPAN&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Example:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;This example enables the scheduler to create two threads and then calls DemoEvent function that takes event class and a Win32 manual-reset event class as template parameters. The Demo function first creates several tasks that simulate some work and then wait for a shared event to become signaled.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt; mso-add-space: auto" class=MsoListParagraphCxSpLast&gt;&lt;FONT size=3 face=Calibri&gt;Special thanks to Rick Molloy for sharing this example.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;// event.cpp : Defines the entry point for the console application.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;//&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;// compile with: /EHsc&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;#include&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: #a31515"&gt;&amp;lt;windows.h&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;#include&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: #a31515"&gt;&amp;lt;concrt.h&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;#include&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: #a31515"&gt;&amp;lt;concrtrm.h&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;#include&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: #a31515"&gt;&amp;lt;ppl.h&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: blue"&gt;namespace&lt;/SPAN&gt; Concurrency;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: blue"&gt;namespace&lt;/SPAN&gt; std;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;class&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; WindowsEvent&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;HANDLE m_event;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;public&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;WindowsEvent()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;:m_event(CreateEvent(NULL,TRUE,FALSE,TEXT(&lt;SPAN style="COLOR: #a31515"&gt;"WindowsEvent"&lt;/SPAN&gt;)))&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;~WindowsEvent()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CloseHandle(m_event);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; set()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SetEvent(m_event);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; wait(&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; count = INFINITE)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;WaitForSingleObject(m_event,count);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;};&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;template&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; EventClass&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;void&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; DemoEvent()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;EventClass e;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;LONG &lt;SPAN style="COLOR: blue"&gt;volatile&lt;/SPAN&gt; taskCtr = 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//create a taskgroup and schedule multiple copies of the task&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;task_group tg;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;for&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; i = 0;i &amp;lt; 8; ++i)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;tg.run([&amp;amp;e, &amp;amp;taskCtr]{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//Simulate some work&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Sleep(100);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;printf_s(&lt;SPAN style="COLOR: #a31515"&gt;"\tTask %d waiting for the event\n"&lt;/SPAN&gt;, InterlockedIncrement(&amp;amp;taskCtr));&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;e.wait();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;});&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Sleep(1000);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;printf_s(&lt;SPAN style="COLOR: #a31515"&gt;"&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Setting the event\n"&lt;/SPAN&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//Set the event&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;e.set();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//wait for the tasks&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;tg.wait();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;void&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; main ()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Create a scheduler that uses two threads.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CurrentScheduler::Create(SchedulerPolicy(2, MinConcurrency, 2, MaxConcurrency, 2));&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;printf_s(&lt;SPAN style="COLOR: #a31515"&gt;"Cooperative Event\n"&lt;/SPAN&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;DemoEvent&amp;lt;&lt;SPAN style="COLOR: blue"&gt;event&lt;/SPAN&gt;&amp;gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;printf_s(&lt;SPAN style="COLOR: #a31515"&gt;"Windows Event\n"&lt;/SPAN&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;DemoEvent&amp;lt;WindowsEvent&amp;gt;();&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-add-space: auto" class=MsoListParagraphCxSpFirst&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Sample Output:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Cooperative Event&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Task 1 waiting for the event&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Task 2 waiting for the event&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Task 3 waiting for the event&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Task 4 waiting for the event&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Task 5 waiting for the event&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Setting the event&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Windows Event&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Task 1 waiting for the event&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Task 2 waiting for the event&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Setting the event&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Task 3 waiting for the event&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Task 4 waiting for the event&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 10pt 0.5in" class=MsoListParagraphCxSpLast&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Task 5 waiting for the event&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;We observe that when using cooperative event, we execute all 5 tasks, each task when waiting on the event that is not set, cooperatively yields so that another task can be scheduled and run in the thread’s quantum. When using windows event, we observe that the 2 tasks scheduled block the thread until the event is set.&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9700258" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/concurrency/default.aspx">concurrency</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Concurrency+Runtime/default.aspx">Concurrency Runtime</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Parallel+Pattern+Library/default.aspx">Parallel Pattern Library</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Asynchronous+Agents/default.aspx">Asynchronous Agents</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_0x/default.aspx">C++0x</category></item><item><title>Introduction to Asynchronous Agents Library</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/06/03/introduction-to-asynchronous-agents-library.aspx</link><pubDate>Thu, 04 Jun 2009 01:08:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9693514</guid><dc:creator>Steve Gates</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9693514.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9693514</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9693514</wfw:comment><description>&lt;p&gt;One of the native concurrency components coming in Visual Studio 2010 is the Asynchronous Agents Library. The goal of the Agents Library is to improve developer productively and enable developers to take advantage of concurrency with an agent-based message passing model to build isolated and composable components. In this blog, I will provide an introduction to the features available in the Asynchronous Agents Library and go into more detail about the agent class itself with an example program.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;An Agent Based Model&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Programming with an agent-based model allows concurrency to be inherently baked into the program from the start. Separating parts of a program into composable and reusable pieces that follow well-defined boundaries to communicate with message passing can tolerate latencies and effectively use parallel resources. By avoiding sharing memory when possible and focusing on data dependencies, scaling performance can be obtained using higher level abstractions, like agents, for parallelism. For more information on agent based models take a look here:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Actor_model#Fundamental_concepts"&gt;http://en.wikipedia.org/wiki/Actor_model#Fundamental_concepts&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Overview of Agents Library Features&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The Agents Library can be broken down into three basic parts:&lt;/p&gt;  &lt;p&gt;&lt;b&gt;The Agent Class&lt;/b&gt; – The agent class itself is intended for course grained parallelism/components that handle larger computationally intensive tasks or collections of smaller tasks. Fundamentally, agents are tasks that have an observable lifecycle and communicate with other agents by using message passing. Agents are NOT intended to be used for fine-grained parallelism; for that, the patterns and constructs in the Parallel Patterns Library are better suited. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Message Blocks&lt;/b&gt; – To enable mechanisms for communicating between asynchronous agents and isolated program components, we provide a collection of various message blocks:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;unbounded_buffer &lt;/li&gt;    &lt;li&gt;overwrite_buffer &lt;/li&gt;    &lt;li&gt;single_assignment &lt;/li&gt;    &lt;li&gt;call &lt;/li&gt;    &lt;li&gt;transformer &lt;/li&gt;    &lt;li&gt;timer &lt;/li&gt;    &lt;li&gt;join &lt;/li&gt;    &lt;li&gt;multitype_join &lt;/li&gt;    &lt;li&gt;choice &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;For example, an unbounded_buffer works very similar to a queue. It collects messages from each of its source blocks and offers them in order to its target blocks.&lt;/p&gt;  &lt;p&gt;In addition, infrastructure for easily creating your own message blocks is included.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Coordination Primitives &lt;/b&gt;– For inserting and removing messages from a group of messaging blocks (a messaging network), we include a set of APIs:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;send &lt;/li&gt;    &lt;li&gt;asend &lt;/li&gt;    &lt;li&gt;receive &lt;/li&gt;    &lt;li&gt;try_receive &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In later blogs, I will dive into the specifics of each message block and coordination primitive explaining how and when to use them.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Agent Class in More Detail&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Essentially an agent is a light weight task (LWT) with observable state and cancellation. The lifecycle of an agent is as follows:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/nativeconcurrency/WindowsLiveWriter/IntroductiontoAsynchronousAgentsLibrary_BD29/AgentStateDiagram_4.jpg"&gt;&lt;img title="AgentStateDiagram" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="222" alt="AgentStateDiagram" src="http://blogs.msdn.com/blogfiles/nativeconcurrency/WindowsLiveWriter/IntroductiontoAsynchronousAgentsLibrary_BD29/AgentStateDiagram_thumb_1.jpg" width="448" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;To see how an agent passes through the states, let’s look at the simplest case creating, starting, and waiting on an agent:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;    MyAgent myagent();&lt;/pre&gt;
&lt;style type="text/css"&gt;







.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;myagent is now in the ‘agent_created’ state.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    myagent.start();&lt;/pre&gt;
&lt;style type="text/css"&gt;







.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Calling start() &lt;font size="2"&gt;moves the agent to&lt;/font&gt; ‘agent_runnable’.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    agent::wait(&amp;amp;myagent);&lt;/pre&gt;
&lt;style type="text/css"&gt;







.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Wait blocks until myagent reaches one of the final states (agent_cancelled, agent_done, or agent_faulted).&lt;/p&gt;

&lt;p&gt;The agent class contains a protected pure virtual run() method which is called when the agent is executed:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;    virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; run() = 0;&lt;/pre&gt;
&lt;style type="text/css"&gt;







.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;When start() is called a light weight task is scheduled and the function will immediately return; once there are available resources the scheduler will start executing the agent task, which will call the run() method when it executes. When an agent is finished, it must call the done() function to signal completion of its work. Commonly, done() is called at the end of the run() function; however, in some circumstances, it may be desirable to decouple the lifetime of the agent from the execution of the run method, such as if the agent does work asynchronously.&lt;/p&gt;

&lt;p&gt;A single agent can be waited on by using the wait function, or multiple agents using the wait_for_one and wait_for_all functions on an array of agents. Waiting on an agent is one way of observing an agents state or status. The two following methods allow for directly querying the status and obtaining a message block to receive from:&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    agent_status status(); 
    ISource&amp;lt;agent_status&amp;gt; * status_port();&lt;/pre&gt;
&lt;style type="text/css"&gt;







.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Agents also can be canceled:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;    bool&lt;/span&gt; cancel();&lt;/pre&gt;
&lt;style type="text/css"&gt;







.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;







.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;If an agent has not started yet and cancel is called it will not be run and its status will be canceled, however if the agent has already started then calling cancel has no effect. Already started agents can’t be stopped.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Agents Sample:&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;To better illustrate agents, consider this implementation of a find string. The program works by searching a directory recursively for files matching an expression and then searching each file for a given string, very similar to ‘findstr’. The program is separated into several agents with specific jobs. One agent is for locating matching files, several for parsing the files looking for the specified string, and one for writing out found matches to the console. This sample also uses unbounded_buffer, asend, and receive.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/nativeconcurrency/WindowsLiveWriter/IntroductiontoAsynchronousAgentsLibrary_BD29/FindStringDiagram_2.jpg"&gt;&lt;img title="FindStringDiagram" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="179" alt="FindStringDiagram" src="http://blogs.msdn.com/blogfiles/nativeconcurrency/WindowsLiveWriter/IntroductiontoAsynchronousAgentsLibrary_BD29/FindStringDiagram_thumb.jpg" width="454" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;FileFinder.h:&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;This agent takes a string containing the type of files to search for. Each matching file found is sent to an unbounded_buffer m_pFileNames which the FileReader agents receive from.&lt;/p&gt;

&lt;p&gt;Here is the run() method. It searches each directory recursively for matching files. A special end message is also used at the end to signal there are no more files. Notice at the end of run() the done() function is called.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; run()
{
    &lt;font color="#0000ff"&gt;wchar_t&lt;/font&gt; currentDirectory[MAX_FILE_NAME] = L&amp;quot;.\\&amp;quot;;
    FindFilesRecursively(currentDirectory);

    &lt;span class="rem"&gt;// Send END_MSG to signal done processing.&lt;/span&gt;
    asend(m_pFileNames, (&lt;font color="#0000ff"&gt;wchar_t&lt;/font&gt; *)END_MSG);
    done(agent_done);
}&lt;/pre&gt;

&lt;p&gt;Here is the code where matching file names are sent to the unbounded_buffer:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;while&lt;/span&gt;(moreFiles)
{
    &lt;span class="rem"&gt;// Copy file name, receiver will be responsible for cleanup.&lt;/span&gt;
    pFileName = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;font color="#0000ff"&gt;wchar_t&lt;/font&gt;[MAX_FILE_NAME];
    wcscpy_s(pFileName, MAX_FILE_NAME, pDirectory);
    wcscat_s(pFileName, MAX_FILE_NAME, findFileData.cFileName);

    &lt;span class="rem"&gt;//&lt;/span&gt;
    &lt;span class="rem"&gt;// Send the filename to the unbounded_buffer.&lt;/span&gt;
    &lt;span class="rem"&gt;//&lt;/span&gt;
    asend(m_pFileNames, pFileName);
    moreFiles = FindNextFile(hFind, &amp;amp;findFileData);
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;FileReader.h:&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;The FileReader agent keeps receiving file names to parse from an input unbounded_buffer and sends any matches to another unbounded_buffer which the ConsoleWriter will receive from.&lt;/p&gt;

&lt;p&gt;Here is the run() method. Notice the while loop that keeps receiving messages, until the end message is reached, from the same unbounded_buffer the FileFinder agent was using.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; run()
{
    &lt;font color="#0000ff"&gt;wchar_t&lt;/font&gt; *pFileName;

    &lt;span class="rem"&gt;//&lt;/span&gt;
    &lt;span class="rem"&gt;// Repeatedly pull filename messages out of the &lt;/span&gt;
    &lt;span class="rem"&gt;// unbounded_buffer to parse until the END_MSG is &lt;/span&gt;
    &lt;span class="rem"&gt;// reached. Note this will ConcRT aware block until&lt;/span&gt;
    &lt;span class="rem"&gt;// a message is avaliable in the buffer.&lt;/span&gt;
    &lt;span class="rem"&gt;//&lt;/span&gt;
    size_t currentLineNum;
    &lt;span class="kwrd"&gt;const&lt;/span&gt; size_t lineSize = 2000;
    &lt;font color="#0000ff"&gt;wchar_t&lt;/font&gt; line[lineSize];
    &lt;span class="kwrd"&gt;while&lt;/span&gt;((&lt;span class="kwrd"&gt;int&lt;/span&gt;)(pFileName = receive(m_pFileNames)) != END_MSG)
    {
        currentLineNum = 1;
        wifstream inputFile;
        inputFile.open(pFileName, ifstream::&lt;span class="kwrd"&gt;in&lt;/span&gt;);
        &lt;span class="kwrd"&gt;while&lt;/span&gt;(inputFile.good() 
            &amp;amp;&amp;amp; inputFile.getline(line, lineSize))
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt;(wcsstr(line, m_pSearchString) != NULL)
            {
                &lt;span class="rem"&gt;//&lt;/span&gt;
                &lt;span class="rem"&gt;// Create a new message payload and send it to &lt;/span&gt;
                &lt;span class="rem"&gt;// the unbounded_buffer for the ConsoleWriter &lt;/span&gt;
                &lt;span class="rem"&gt;// to receive from.&lt;/span&gt;
                &lt;span class="rem"&gt;//&lt;/span&gt;
                asend(m_pFoundBuffer, &lt;span class="kwrd"&gt;new&lt;/span&gt; Payload(pFileName, 
                    wcsnlen(pFileName, MAX_FILE_NAME)+1,
                    currentLineNum,
                    line,
                    wcsnlen(line, lineSize)+1));
            }

            ++currentLineNum;
            line[0] = &lt;span class="str"&gt;'\0'&lt;/span&gt;;
        }
        inputFile.close();
        &lt;font color="#0000ff"&gt;delete&lt;/font&gt; pFileName;
    }

    &lt;span class="rem"&gt;// Resend the END_MSG for any other FileReaders.&lt;/span&gt;
    asend(m_pFileNames, (&lt;font color="#0000ff"&gt;wchar_t&lt;/font&gt; *)END_MSG);
    done(agent_done);
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;ConsoleWriter.h:&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;This agent receives messages containing information about found matches and prints the information to the console.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Here is a snippet from its run method. It loops receiving messages from the unbounded_buffer the FileReaders send to.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;//&lt;/span&gt;
&lt;span class="rem"&gt;// Keep receiving messages to print to the console until&lt;/span&gt;
&lt;span class="rem"&gt;// the END_MSG is received. Note this will ConcRT aware&lt;/span&gt;
&lt;span class="rem"&gt;// block until a message is avaliable in the buffer.&lt;/span&gt;
&lt;span class="rem"&gt;//&lt;/span&gt;
&lt;span class="kwrd"&gt;while&lt;/span&gt;((&lt;span class="kwrd"&gt;int&lt;/span&gt;)(pPayload = receive(m_pFoundBuffer)) != END_MSG)
{
    SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE 
        | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY); 
    printf(&lt;span class="str"&gt;&amp;quot;%ls:%lu:&amp;quot;&lt;/span&gt;, pPayload-&amp;gt;m_pFileName, 
        (&lt;font color="#0000ff"&gt;unsigned&lt;/font&gt; &lt;span class="kwrd"&gt;long&lt;/span&gt;)pPayload-&amp;gt;m_lineNumber);
    SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE 
        | FOREGROUND_GREEN | FOREGROUND_RED);
    printf(&lt;span class="str"&gt;&amp;quot;:%ls\n&amp;quot;&lt;/span&gt;, pPayload-&amp;gt;m_pLine);
    &lt;font color="#0000ff"&gt;delete&lt;/font&gt; pPayload;
}&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;Payload.h&lt;/b&gt;:&lt;/p&gt;

&lt;p&gt;Defines a class used to pass messages between FileReaders and the ConsoleWriter. It holds the file name a match was found in, the line number, and the line itself.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;FindString.cpp&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Driver of the program creates, starts, and then waits on all the agents.&lt;/p&gt;

&lt;p&gt;Here is the code to create the unbounded_buffers:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    unbounded_buffer&amp;lt;&lt;font color="#0000ff"&gt;wchar_t&lt;/font&gt; *&amp;gt; fileBuffer;
    unbounded_buffer&amp;lt;Payload *&amp;gt; foundBuffer;&lt;/pre&gt;

&lt;p&gt;Creation of the agents:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;// Agent to find files.&lt;/span&gt;
FileFinder fileFinder(pFilePattern, &amp;amp;fileBuffer);
fileFinder.start();

&lt;span class="rem"&gt;// Agents to handle parsing files.&lt;/span&gt;
FileReader **ppFileReaderAgents = &lt;span class="kwrd"&gt;new&lt;/span&gt; FileReader*[numAgents];
&lt;span class="kwrd"&gt;for&lt;/span&gt;(&lt;font color="#0000ff"&gt;unsigned&lt;/font&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; numAgents; ++i)
{
    ppFileReaderAgents[i] = &lt;span class="kwrd"&gt;new&lt;/span&gt; FileReader(&amp;amp;fileBuffer, 
        pStringPattern, &amp;amp;foundBuffer);
    ppFileReaderAgents[i]-&amp;gt;start();
}

&lt;span class="rem"&gt;// Agent to handle writing to the console.&lt;/span&gt;
ConsoleWriter consoleWriter(&amp;amp;foundBuffer);
consoleWriter.start();&lt;/pre&gt;

&lt;p&gt;Waiting on the agents to finish:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;// Wait for agents to finish.&lt;/span&gt;
agent::wait(&amp;amp;fileFinder);
&lt;span class="kwrd"&gt;for&lt;/span&gt;(&lt;font color="#0000ff"&gt;unsigned&lt;/font&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; numAgents; ++i)
{
    agent::wait(ppFileReaderAgents[i]);
    delete ppFileReaderAgents[i];
}
&lt;font color="#0000ff"&gt;delete&lt;/font&gt; [] ppFileReaderAgents;

&lt;span class="rem"&gt;// Now that all other agents have finished signal the ConsoleWriter&lt;/span&gt;
&lt;span class="rem"&gt;// it can finish.&lt;/span&gt;
send(foundBuffer, (Payload *)END_MSG);
agent::wait(&amp;amp;consoleWriter);&lt;/pre&gt;

&lt;p&gt;In this program, I created agents to each handle large chunks of isolated work and I/O. Notice how parallelism is built in to the program by using higher levels of abstraction from the beginning. I created a pipeline of agents that work concurrently together with almost no knowledge of each other. Each agent takes in messages, performs some action, and then accordingly sends a message. Since each agent can be running at the same time I can exploit any available cores on the system; notice how there are many FileReader agents used, this means the program will be parsing multiple files concurrently at the same time. By designing my program in this fashion I can easily add, remove, or modify individual agents without needed to restructure anything else. I also avoided having to deal explicitly with locks and other difficult forms of synchronization.&lt;/p&gt;

&lt;p&gt;To see all the code and play around with this sample download the project and source files here:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://code.msdn.microsoft.com/concrtextras" target="_blank"&gt;Code Samples&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Example command line execution of this program is:&lt;/p&gt;

&lt;p&gt;FindString.exe agents *.txt&lt;/p&gt;

&lt;p&gt;In future posts, I will go into more detail about each message block the Asynchronous Agents Library provides, how to use them, the coordination primitives, and how to take advantage of our infrastructure and easily construct your own message blocks.&lt;/p&gt;
&lt;style type="text/css"&gt;





.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9693514" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/concurrency/default.aspx">concurrency</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Asynchronous+Agents/default.aspx">Asynchronous Agents</category></item><item><title>Samples posted for the Parallel Pattern Library and Concurrency Runtime</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/06/02/samples-posted-for-the-parallel-pattern-library-and-concurrency-runtime.aspx</link><pubDate>Wed, 03 Jun 2009 00:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9687311</guid><dc:creator>rickmolloy</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9687311.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9687311</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9687311</wfw:comment><description>&lt;P&gt;Following&amp;nbsp;the release of Visual Studio 2010, we've just published a set of &lt;A class="" href="http://code.msdn.microsoft.com/concrtextras" mce_href="http://code.msdn.microsoft.com/concrtextras"&gt;sample applications&lt;/A&gt; for using the Parallel Pattern Library, the Agents Library and the Concurrency Runtime on code gallery.&amp;nbsp; These supplement the &lt;A href="http://msdn.microsoft.com/en-us/library/dd504870(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd504870(VS.100).aspx"&gt;documentation and samples&lt;/A&gt; provided on msdn for Beta1.&lt;/P&gt;
&lt;P&gt;The samples include using task parallelism with PPL, a&amp;nbsp;few based&amp;nbsp;examples of using the Agents Library (Dining Philosophers, an example using choice) and a find in files example (which will be blogged about here in the next day or so).&amp;nbsp; There are also some examples of using the Concurrency Runtime itself, a simple &lt;A class="" href="http://msdn.microsoft.com/en-us/library/dd492846(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd492846(VS.100).aspx"&gt;event&lt;/A&gt; based application demonstrating cooperative blocking and UMS threads and a task based example (fibonacci) which shows the &lt;A class="" href="http://msdn.microsoft.com/en-us/library/dd492420(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd492420(VS.100).aspx"&gt;Concurrent Suballocator&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;As always your feedback here or in the &lt;A class="" href="http://social.msdn.microsoft.com/Forums/en-US/parallelcppnative/threads/" mce_href="http://social.msdn.microsoft.com/Forums/en-US/parallelcppnative/threads/"&gt;forums&lt;/A&gt; is welcome.&lt;/P&gt;
&lt;P&gt;-Rick&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9687311" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/concurrency/default.aspx">concurrency</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Concurrency+Runtime/default.aspx">Concurrency Runtime</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Parallel+Pattern+Library/default.aspx">Parallel Pattern Library</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Asynchronous+Agents/default.aspx">Asynchronous Agents</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Win7/default.aspx">Win7</category></item><item><title>Auction Simulation written in the Asynchronous Agents Library</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/05/30/auction-simulation-written-in-the-asynchronous-agents-library.aspx</link><pubDate>Sat, 30 May 2009 10:11:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9663707</guid><dc:creator>rickmolloy</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9663707.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9663707</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9663707</wfw:comment><description>&lt;p&gt;One of our architects, Niklas Gustafsson &lt;a href="http://blogs.msdn.com/concurrently_speaking/archive/2009/05/29/auction-simulation-in-c.aspx"&gt;has just posted &lt;/a&gt;an actor based auction simulation written in the Asynchronous Agents Library. If you follow the blog trail back, you'll see that this was &lt;a href="http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk/docs/examples/actors/auction.scala"&gt;implemented originally in scala&lt;/a&gt; and that Matthew Podwysocki &lt;a href="http://codebetter.com/blogs/matthew.podwysocki/archive/2009/05/20/f-actors-revisited.aspx"&gt;has implemented this in F#&lt;/a&gt;. Niklas also alluded to, but hasn't shared yet an implementation &lt;a href="http://blogs.msdn.com/maestroteam"&gt;built in Axum&lt;/a&gt;.&amp;#160; I find it fascinating to compare and contrast the implementations for similarities and differences.&lt;strong&gt; &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;It’s also worth stressing his concluding remarks here which really highlight why we’re providing an asynchronous message passing and actor based programming model:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;As a parting thought, I want to draw your attention to one simple fact: we just wrote an application with 17 agents working together on a problem in parallel, interacting in non-trivial patterns updating state and arriving at a shared understanding of “their world” without a single lock, mutex, or critical section.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The ability to write such complex and concurrent code without dealing with the headaches of managing synchronization primitives is incredibly exciting (at least to me it is), so go check this out.&lt;/p&gt;  &lt;p&gt;-Rick&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9663707" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Asynchronous+Agents/default.aspx">Asynchronous Agents</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_0x/default.aspx">C++0x</category></item><item><title>Implementing Dining Philosophers with the Agents Library</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/05/28/implementing-dining-philosophers-with-the-agents-library.aspx</link><pubDate>Thu, 28 May 2009 22:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9648881</guid><dc:creator>rickmolloy</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9648881.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9648881</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9648881</wfw:comment><description>&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;The &lt;A title="msdn magazine" href="http://msdn.microsoft.com/en-us/magazine/dd882512.aspx" mce_href="http://msdn.microsoft.com/en-us/magazine/dd882512.aspx"&gt;latest issue of msdn magazine&lt;/A&gt; includes an article that I wrote which illustrates implementing the Dining Philosophers purely in message passing and without using any explicit locking.&amp;nbsp; If you have Visual Studio 2010 Beta1 installed, you can also &lt;A href="http://code.msdn.microsoft.com/mag200906ConcurrentA" mce_href="http://code.msdn.microsoft.com/mag200906ConcurrentA"&gt;download the code and build the project&lt;/A&gt;, even if you don't you can &lt;A href="http://msdn.microsoft.com/en-us/magazine/dd875475.aspx" mce_href="http://msdn.microsoft.com/en-us/magazine/dd875475.aspx"&gt;&lt;FONT color=#0000ff&gt;browse the code &lt;/FONT&gt;&lt;/A&gt;online.&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;For folks that are curious about how locks are avoided, I'll state that the chopsticks themselves are messages and&amp;nbsp;rather than the classic solution with semaphores, the&amp;nbsp;philosopher uses the &lt;A href="http://msdn.microsoft.com/en-us/library/dd728075(VS.100).aspx"&gt;join message block&lt;/A&gt; to receive both messages from the table when it is time to pick them up. i.e. the code looks like this:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 10pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;vector&amp;lt;Chopstick*&amp;gt; PickupChopsticks() &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 10pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 10pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;//create the join&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 10pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;join&amp;lt;Chopstick*,non_greedy&amp;gt; j(2);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 10pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;m_LeftChopstickProvider-&amp;gt;link_target(&amp;amp;j); &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 10pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;m_RightChopstickProvider-&amp;gt;link_target(&amp;amp;j);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 10pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 10pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;//pickup the chopsticks&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 10pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; receive(j);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt 0.5in" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; FONT-SIZE: 10pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;I'd encourage you to read the article and provide feedback either here or &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/parallelcppnative/threads/" mce_href="http://social.msdn.microsoft.com/Forums/en-US/parallelcppnative/threads/"&gt;in our forums&lt;/A&gt;.&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; FONT-SIZE: 10pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;-Rick&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9648881" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/concurrency/default.aspx">concurrency</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Concurrency+Runtime/default.aspx">Concurrency Runtime</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Asynchronous+Agents/default.aspx">Asynchronous Agents</category></item><item><title>What's new in the Concurrency Runtime and the Parallel Patterns and Asynchronous Agents Libraries</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/05/21/what-s-new-in-the-concurrency-runtime-and-the-parallel-patterns-and-asynchronous-agents-libraries.aspx</link><pubDate>Thu, 21 May 2009 23:23:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634271</guid><dc:creator>rickmolloy</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9634271.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9634271</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9634271</wfw:comment><description>&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;Visual Studio 2010 Beta1 has been released, and it is a &lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=85520793-68fc-4361-a8b6-dc2cff49c8d2&amp;amp;displaylang=en"&gt;full install version&lt;/A&gt;.&amp;nbsp; The team has been busy, busy busy since the CTP release last fall to deliver most of the APIs and objects we’ve blogged about here&amp;nbsp;into Beta1.&amp;nbsp; So I wanted to take a moment to summarize what’s new in the Beta for the Parallel Pattern Library, the Asynchronous Agents Library and the Concurrency Runtime.&amp;nbsp; &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;You can find the official reference documentation and walkthroughs in the MSDN Library &lt;A href="http://msdn.microsoft.com/en-us/library/dd504870(VS.100).aspx"&gt;here&lt;/A&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;H3 style="MARGIN: auto 0in"&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: black; mso-fareast-font-family: 'Times New Roman'"&gt;What’s new in the Parallel Patterns Library&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/H3&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: black; FONT-SIZE: 10pt"&gt;The &lt;A href="http://msdn.microsoft.com/en-us/library/dd492418(VS.100).aspx"&gt;Parallel Patterns Library&lt;/A&gt; (PPL) provides an imperative programming model that promotes scalability and ease-of-use for developing concurrent applications. &amp;nbsp;In general the library’s surface area remains largely unchanged, with a few high impact additions.&amp;nbsp; You will also find it more stable, more robust, faster, and more scalable – lots of goodness!&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL type=disc&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: black; mso-list: l0 level1 lfo1; tab-stops: list .5in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;Added support for&lt;B&gt; exception handling in &lt;A href="http://msdn.microsoft.com/en-us/library/dd470722(VS.100).aspx"&gt;task_group&lt;/A&gt;&lt;/B&gt;.&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: black; mso-list: l0 level1 lfo1; tab-stops: list .5in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;The new &lt;B&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd505033(VS.100).aspx"&gt;is_current_task_group_canceling&lt;/A&gt;&lt;/B&gt; API helps query cancellation status.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: black; mso-list: l0 level1 lfo1; tab-stops: list .5in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;The &lt;B&gt;&lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2008/09/25/avoiding-contention-using-combinable-objects.aspx"&gt;&lt;FONT color=#0000ff&gt;combinable&amp;lt;T&amp;gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/B&gt; object has been added for helping avoid races on reductions and accumulations.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: black; mso-list: l0 level1 lfo1; tab-stops: list .5in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;We’ve made &lt;B&gt;significant performance improvements&lt;/B&gt; to our &lt;A href="http://msdn.microsoft.com/en-us/library/dd470426(VS.100).aspx"&gt;parallel loops&lt;/A&gt;: parallel_for, parallel_for_each and parallel_invoke &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: black; mso-list: l0 level1 lfo1; tab-stops: list .5in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class=MsoNormal&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;&lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2009/04/22/synchronization-with-the-concurrency-runtime.aspx"&gt;&lt;FONT color=#0000ff&gt;critical_section&lt;/FONT&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt; and &lt;B&gt;&lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2009/05/14/synchronization-with-the-concurrency-runtime-part-2.aspx"&gt;&lt;FONT color=#0000ff&gt;reader_writer&lt;/FONT&gt;&lt;/A&gt;, &lt;/B&gt;the &lt;A href="http://msdn.microsoft.com/en-us/library/dd759350(VS.100).aspx"&gt;cooperative synchronization primitives&lt;/A&gt; that we blogged about recently, are now in. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: black; mso-list: l0 level1 lfo1; tab-stops: list .5in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;We’ve also included a manual reset event called &lt;B&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd492846(VS.100).aspx"&gt;Concurrency::event&lt;/A&gt;&lt;/B&gt;. &amp;nbsp;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;H3 style="MARGIN: auto 0in"&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: black; mso-fareast-font-family: 'Times New Roman'"&gt;What’s new in the Asynchronous Agents Library&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/H3&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: black; FONT-SIZE: 10pt"&gt;The &lt;A href="http://msdn.microsoft.com/en-us/library/dd492627(VS.100).aspx"&gt;Asynchronous Agents Library&lt;/A&gt; (or just &lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;Agents Library&lt;SPAN style="COLOR: black"&gt;) provides a programming model that enables you to increase the robustness of concurrency-enabled application development. The Agents Library is a C++ template library that promotes an actor-based programming model and in-process message passing for fine-grained dataflow and pipelining tasks. The Agents Library builds upon the scheduling and resource management components of the Concurrency Runtime.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: black; FONT-SIZE: 10pt"&gt;Here’s a summary of what’s we’ve added and revised in the Agents library:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL type=disc&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: black; mso-list: l1 level1 lfo2; tab-stops: list .5in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;Added the &lt;B&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd504833(VS.100).aspx#choice"&gt;&lt;FONT color=#0000ff&gt;choice&lt;/FONT&gt;&lt;/A&gt;&lt;/B&gt;, &lt;B&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd504833(VS.100).aspx#join"&gt;&lt;FONT color=#0000ff&gt;join &lt;SPAN style="FONT-WEIGHT: normal"&gt;and&lt;/SPAN&gt; multitype_join&lt;/FONT&gt;&lt;/A&gt;&lt;/B&gt; message blocks to allow users to wait on a set of messages; choice waits for any message, join waits for all messages of a single type, and multitype_join waits for all messages and allows for multiple different types.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: black; mso-list: l1 level1 lfo2; tab-stops: list .5in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;Renamed the transform message block to &lt;B&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd504833(VS.100).aspx#transformer"&gt;&lt;FONT color=#0000ff&gt;transformer&lt;/FONT&gt;&lt;/A&gt;&lt;/B&gt; (we didn’t want Concurrency::transformer to conflict with std::transform) &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: black; mso-list: l1 level1 lfo2; tab-stops: list .5in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class=MsoNormal&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;Added functor support&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt; to the pipeline message blocks &lt;B&gt;call&lt;/B&gt; and &lt;B&gt;transformer&lt;/B&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: black; mso-list: l1 level1 lfo2; tab-stops: list .5in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class=MsoNormal&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;Building custom message blocks is now easier&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt; due to some refactoring.&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;H3 style="MARGIN: auto 0in"&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: black; mso-fareast-font-family: 'Times New Roman'"&gt;What’s new and improved in the Concurrency Runtime itself&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/H3&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: black; FONT-SIZE: 10pt"&gt;The underlying Concurrency Runtime has undergone significant feature improvements and performance enhancements, many of which we have been discussing already on this blog.&amp;nbsp; These changes will have improvements to everything built on top of the runtime, including the Parallel Patterns Library and the Agents Library.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL type=disc&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: black; mso-list: l2 level1 lfo3; tab-stops: list .5in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class=MsoNormal&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;Added support for User Mode Scheduled Threads&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt; on Windows 7 RC (see our blog posts on the &lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2009/02/04/concurrency-runtime-and-windows-7.aspx"&gt;Concurrency Runtime’s support&lt;/A&gt; and &lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2009/02/02/dave-probert-goes-deep-on-win7-user-mode-scheduled-threads.aspx"&gt;&lt;FONT color=#0000ff&gt;go deep on Win7 UMS&lt;/FONT&gt;&lt;/A&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: black; mso-list: l2 level1 lfo3; tab-stops: list .5in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class=MsoNormal&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;Revised and simplified &lt;A href="http://msdn.microsoft.com/en-us/library/dd470841(VS.100).aspx"&gt;scheduler policies&lt;/A&gt; and APIs&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt; for &lt;A href="http://msdn.microsoft.com/en-us/library/dd492385(VS.100).aspx"&gt;constructing schedulers&lt;/A&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: black; mso-list: l2 level1 lfo3; tab-stops: list .5in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;Added &lt;B&gt;dynamic resource management&lt;/B&gt; for load balancing between multiple scheduler instances.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: black; mso-list: l2 level1 lfo3; tab-stops: list .5in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;Further improved load balancing by applying the &lt;B&gt;hill climbing&lt;/B&gt; technique to thread injection.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN: 0in 0in 0pt; COLOR: black; mso-list: l2 level1 lfo3; tab-stops: list .5in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;Added the &lt;B&gt;concurrent sub-allocator&lt;/B&gt; for &lt;A href="http://msdn.microsoft.com/en-us/library/dd492420(VS.100).aspx"&gt;high performance allocations&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/library/dd470885(VS.100).aspx"&gt;frees&lt;/A&gt; on multiple threads&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;H3 style="MARGIN: auto 0in"&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: black; mso-fareast-font-family: 'Times New Roman'"&gt;Call to Action&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: black; FONT-WEIGHT: normal; mso-fareast-font-family: 'Times New Roman'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/H3&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: black; FONT-SIZE: 10pt"&gt;&lt;A href="http://www.microsoft.com/visualstudio/en-gb/products/2010/default.mspx"&gt;&lt;FONT color=#0000ff&gt;Download and install Microsoft Visual Studio 2010 Beta 1&lt;/FONT&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: black; FONT-SIZE: 10pt"&gt; today.&amp;nbsp; Impress your friends and coworkers by being among the first to learn and use our libraries.&amp;nbsp; Provide early and critical feedback &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/parallelcppnative/threads/"&gt;on our forum&lt;/A&gt; that will shape the way that these libraries are ultimately released.&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: black; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: black; FONT-SIZE: 10pt"&gt;See this blog post on the value of your feedback:&amp;nbsp; &lt;A href="http://blogs.msdn.com/pfxteam/archive/2008/06/02/8567825.aspx"&gt;&lt;FONT color=#0000ff&gt;On Achieving Perfection –or– Why We Love Your Feedback (and Why You Can Love Giving It)&lt;/FONT&gt;&lt;/A&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: black; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; COLOR: black; FONT-SIZE: 10pt"&gt;Happy coding!&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face="Times New Roman"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9634271" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/concurrency/default.aspx">concurrency</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Concurrency+Runtime/default.aspx">Concurrency Runtime</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Parallel+Pattern+Library/default.aspx">Parallel Pattern Library</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Asynchronous+Agents/default.aspx">Asynchronous Agents</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_0x/default.aspx">C++0x</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Win7/default.aspx">Win7</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/UMS/default.aspx">UMS</category></item><item><title>Synchronization with the Concurrency Runtime - Part 2</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/05/14/synchronization-with-the-concurrency-runtime-part-2.aspx</link><pubDate>Thu, 14 May 2009 21:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9616831</guid><dc:creator>vinodsu</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9616831.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9616831</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9616831</wfw:comment><description>&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;In my previous post, I addressed the motivation behind using concurrency runtime’s synchronization primitives and also introduced Critical Section. In this blog, I will cover concurrency runtime’s reader writer lock.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Reader Writer Lock&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt; mso-add-space: auto" class=MsoListParagraph&gt;&lt;FONT size=3 face=Calibri&gt;This class enables multiple threads to read from a shared resource at the same time but only allows one thread to write to it at a time. They share many characteristics with concurrency runtime’s critical section, reader writer locks are non-reentrant and block cooperatively. The reader writer lock resembles the Win32 Slim reader/writer locks (&lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/aa904937(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa904937(VS.85).aspx"&gt;&lt;FONT color=#0000ff size=3 face=Calibri&gt;SRWLock&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3 face=Calibri&gt;).&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Reader writer lock performs better than critical section in read-mostly environments. &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Similarity to Win32 Slim reader/writer locks:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l0 level1 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpFirst&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;Can be used only by threads of a single process. &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l0 level1 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;The reader writer lock can be owned by multiple reader-threads or only one writer thread at any time.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l0 level1 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;Non-reentrant.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 19.5pt; mso-list: l0 level1 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpLast&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;Do not support upgrades or downgrades.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Differences with Win32 Slim reader/writer locks:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l0 level1 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpFirst&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;The concurrency runtime’s reader writer lock object guarantees that the order of exclusive (writer) lock-ownership is on a first-come, first-serve basis.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l0 level1 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;There is no need to explicitly call Initialization of resources before use of the concurrency runtime’s reader writer lock and release after the use of the reader writer lock.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l0 level1 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;Cannot specify spin count for the concurrency runtime’s reader writer lock object.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l0 level1 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;The concurrency runtime’s reader writer lock enforces cooperative blocking where they yield to other cooperative tasks in the runtime when blocked.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l0 level1 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;The concurrency runtime’s reader writer locks give writer preference over readers; i.e. if there are readers and writer(s) simultaneously waiting for the lock, the lock would be handed over to the first writer in queue.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l0 level1 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Exceptions are thrown by the concurrency runtime’s reader writer lock object; on recursive calls, or if unlock is called when the lock is not held, or if a lock is destroyed when being held.&lt;I style="mso-bidi-font-style: normal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/I&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Example:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;FONT size=3 face=Calibri&gt;Given below is a code sample illustrating reader_writer_lock using 4 readers and 1 writer. The readers output the value of the shared data and the writer updates the value of the shared data and outputs it.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt; mso-add-space: auto" class=MsoListParagraphCxSpLast&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;// reader_writer_lock.cpp&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;// compile with: /EHsc&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;#include&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: #a31515"&gt;&amp;lt;ppl.h&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;#include&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: #a31515"&gt;&amp;lt;stdio.h&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;#include&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: #a31515"&gt;&amp;lt;windows.h&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: blue"&gt;namespace&lt;/SPAN&gt; std;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: blue"&gt;namespace&lt;/SPAN&gt; Concurrency;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;//number of iterations each thread performs&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;static&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: blue"&gt;const&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; NUM_ITERATIONS = 2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;//the shared data that needs protection from race/tearing&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;static&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: blue"&gt;unsigned&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; sharedData = 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;//Demonstrates the use of the reader lock&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;void&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; Reader(reader_writer_lock* pRWLock)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;for&lt;/SPAN&gt;( &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; i = 0; i &amp;lt; NUM_ITERATIONS; ++i)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//use the reader lock&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;pRWLock-&amp;gt;lock_read();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;printf_s(&lt;SPAN style="COLOR: #a31515"&gt;"Reading %d\n"&lt;/SPAN&gt;, sharedData);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//Sleep for some time, this is to simulate potential work done while holding the lock&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Sleep(100);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//release the lock&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;pRWLock-&amp;gt;unlock();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;//Demonstrates the use of the writer lock&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;void&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; Writer(reader_writer_lock* pRWLock)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;for&lt;/SPAN&gt;( &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; i = 0; i &amp;lt; NUM_ITERATIONS; ++i)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//use the writer lock&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;pRWLock-&amp;gt;lock();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;printf_s(&lt;SPAN style="COLOR: #a31515"&gt;"\tWriting %d\n"&lt;/SPAN&gt;, ++sharedData);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//Sleep for some time, this is to simulate potential work done while holding the lock&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Sleep(100);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//release the lock&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;pRWLock-&amp;gt;unlock();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;int&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;reader_writer_lock rwlock;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//performs reader writer operations in parallel&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;parallel_invoke(&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[&amp;amp;] { Reader(&amp;amp;rwlock); },&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[&amp;amp;] { Reader(&amp;amp;rwlock); },&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[&amp;amp;] { Reader(&amp;amp;rwlock); },&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[&amp;amp;] { Reader(&amp;amp;rwlock); },&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[&amp;amp;] { Writer(&amp;amp;rwlock); }&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-add-space: auto" class=MsoListParagraphCxSpFirst&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT size=3 face=Calibri&gt;Sample output:&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in; tab-stops: 0in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Reading 0&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in; tab-stops: 0in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Reading 0&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in; tab-stops: 0in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Reading 0&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in; tab-stops: 0in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Writing 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in; tab-stops: 0in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Reading 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in; tab-stops: 0in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Reading 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in; tab-stops: 0in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Reading 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in; tab-stops: 0in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Reading 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in; tab-stops: 0in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Writing 2&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.5in; tab-stops: 0in" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Reading 2&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt; mso-add-space: auto" class=MsoListParagraphCxSpLast&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;An interesting point to note here is that even though we use 4 readers, we notice that only 3 readers output their value and the lock is taken by the writer. This happens because the lock prefers writers. We do not guarantee the order of task execution but if such a guarantee is required, you could consider using events, which I will cover in the next blog post.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9616831" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/concurrency/default.aspx">concurrency</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Concurrency+Runtime/default.aspx">Concurrency Runtime</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Parallel+Pattern+Library/default.aspx">Parallel Pattern Library</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Asynchronous+Agents/default.aspx">Asynchronous Agents</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_0x/default.aspx">C++0x</category></item><item><title>Synchronization with the Concurrency Runtime - Part 1</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/04/22/synchronization-with-the-concurrency-runtime.aspx</link><pubDate>Wed, 22 Apr 2009 23:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9563099</guid><dc:creator>vinodsu</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9563099.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9563099</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9563099</wfw:comment><description>&lt;P mce_keep="true"&gt;&lt;FONT size=3 face=Calibri&gt;In a concurrent world multiple entities work together to achieve a common goal. A common way to interact and coordinate is to use shared data.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;However, shared data must be accessed carefully. This can be achieved through synchronization, primarily using: &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.75in; mso-list: l2 level1 lfo2; mso-add-space: auto" class=MsoListParagraphCxSpFirst&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;i)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Blocking methods such as locks and mutexes &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 10pt 0.75in; mso-list: l2 level1 lfo2; mso-add-space: auto" class=MsoListParagraphCxSpLast&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;ii)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;Non-blocking methods such as lock-free programming techniques.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;I will talk about the synchronization using blocking methods within a process, using constructs provided as part of the concurrency runtime and exposed through the Parallel Pattern Library (PPL). In this blog, I will address the concurrency runtime’s critical section and will cover reader writer lock and events in subsequent blog posts.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;For a general picture of the native concurrency runtime, and high level roles of each of its components please refer to &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2009/01/12/an-introduction-to-native-concurrency-in-visual-studio-2010.aspx" mce_href="http://blogs.msdn.com/nativeconcurrency/archive/2009/01/12/an-introduction-to-native-concurrency-in-visual-studio-2010.aspx"&gt;&lt;FONT color=#0000ff size=3 face=Calibri&gt;this&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3 face=Calibri&gt; post.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Motivation&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;Goals of the concurrency runtime’s synchronization primitives:&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l0 level1 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpFirst&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;1.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;Simple APIs&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle&gt;&lt;FONT size=3 face=Calibri&gt;Unlike their Win32 equivalent, concurrency runtime’s synchronization primitives don’t have C-style initialization and release/destroy type of resource management calls. The exposed interfaces are simple and conform to the &lt;/FONT&gt;&lt;A href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf" mce_href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf"&gt;&lt;FONT color=#0000ff size=3 face=Calibri&gt;C++0x standards&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3 face=Calibri&gt; and the synchronization objects throw meaningful exceptions on certain illegal operations.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l0 level1 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;2.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;Block in a cooperative manner&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt 0.5in" class=MsoListParagraphCxSpLast&gt;&lt;FONT size=3 face=Calibri&gt;The synchronization objects are cooperative in nature, in that they yield to other cooperative tasks in the runtime in addition to preempting.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;For an illustration of this scenario, refer to &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2009/02/04/concurrency-runtime-and-windows-7.aspx" mce_href="http://blogs.msdn.com/nativeconcurrency/archive/2009/02/04/concurrency-runtime-and-windows-7.aspx"&gt;&lt;FONT color=#0000ff size=3 face=Calibri&gt;this&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3 face=Calibri&gt; post. &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Critical Section&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt; mso-add-space: auto" class=MsoListParagraph&gt;&lt;FONT size=3 face=Calibri&gt;This represents a non-reentrant, cooperative mutual exclusion object that uses concurrency runtime’s facilities to enable cooperative scheduling of work when blocked. This class satisfies all Mutex requirements specified in &lt;/FONT&gt;&lt;A href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf" mce_href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf"&gt;&lt;FONT color=#0000ff size=3 face=Calibri&gt;C++0x standards&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3 face=Calibri&gt;. The concurrency runtime’s critical section provides a C++ façade as compared to its C-styled Win32 equivalent:&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Windows &lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/ms682530(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms682530(VS.85).aspx"&gt;&lt;FONT color=#0000ff size=3 face=Calibri&gt;CRITICAL_SECTION&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Similarity to the Win32 CRITICAL_SECTION:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l1 level1 lfo3; mso-add-space: auto" class=MsoListParagraphCxSpFirst&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;Can be used only by threads of a single process. &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 19.5pt; mso-list: l1 level1 lfo3; mso-add-space: auto" class=MsoListParagraphCxSpLast&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;The critical section object can only be owned by one thread at a time.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Differences with Win32 CRITICAL_SECTION:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l1 level1 lfo3; mso-add-space: auto" class=MsoListParagraphCxSpFirst&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;The concurrency runtime’s critical sections are non-recursive. Exceptions are thrown upon recursive calls.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l1 level1 lfo3; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;The concurrency runtime’s critical section object guarantees that threads waiting on a critical section acquire it on a first-come, first-serve basis.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l1 level1 lfo3; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;There is no need to explicitly call Initialization/allocation of resources before use of the concurrency runtime’s critical section and release resources after the use of the critical section.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l1 level1 lfo3; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;Cannot specify spin count for the concurrency runtime’s critical section object.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l1 level1 lfo3; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;The concurrency runtime’s critical section enforces cooperative blocking where they yield to other cooperative tasks in the runtime when blocked.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 19.5pt; mso-list: l1 level1 lfo3; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-fareast-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3 face=Calibri&gt;Exceptions are thrown by the concurrency runtime’s critical section object; on unlock calls when the lock is not held, or if a lock is destroyed when being held.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt 19.5pt; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -19.5pt; MARGIN: 0in 0in 0pt 19.5pt; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Example:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -19.5pt; MARGIN: 0in 0in 0pt 19.5pt; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;FONT size=3 face=Calibri&gt;The sample below alternates between printing to standard output from FunctionA and FunctionB.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt 19.5pt; mso-add-space: auto" class=MsoListParagraphCxSpLast&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;// critical_section.cpp&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;// compile with: /EHsc&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;#include&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: #a31515"&gt;&amp;lt;ppl.h&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;#include&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: #a31515"&gt;&amp;lt;stdio.h&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;#include&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: #a31515"&gt;&amp;lt;windows.h&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: blue"&gt;namespace&lt;/SPAN&gt; std;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: blue"&gt;namespace&lt;/SPAN&gt; Concurrency;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;//number of iterations each thread performs&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;static&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: blue"&gt;const&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; NUM_ITERATIONS = 5;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;//Demonstrates use of critical section&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;void&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; FunctionA(critical_section* pMutex)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;for&lt;/SPAN&gt;( &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; i = 0; i &amp;lt; NUM_ITERATIONS; ++i)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//use exclusive lock&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;pMutex-&amp;gt;lock();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;printf_s(&lt;SPAN style="COLOR: #a31515"&gt;"A %d\n"&lt;/SPAN&gt;, i);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//Sleep for some time, this is to simulate potential work done while holding the lock&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Sleep(100);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//release exclusive lock&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;pMutex-&amp;gt;unlock();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: green; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;//Demonstrates use of critical section&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;void&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; FunctionB(critical_section* pMutex)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;for&lt;/SPAN&gt;( &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; i = 0; i &amp;lt; NUM_ITERATIONS; ++i)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//use exclusive lock&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;pMutex-&amp;gt;lock();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;printf_s(&lt;SPAN style="COLOR: #a31515"&gt;"\tB %d\n"&lt;/SPAN&gt;, i);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//Sleep for some time, this is to simulate potential work done while holding the lock&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Sleep(100);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//release exclusive lock&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;pMutex-&amp;gt;unlock();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;int&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;critical_section mutex;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//call FunctionA and FunctionB in parallel&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;parallel_invoke(&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[&amp;amp;] { FunctionA(&amp;amp;mutex); },&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;[&amp;amp;] { FunctionB(&amp;amp;mutex); }&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt 19.5pt; mso-add-space: auto" class=MsoListParagraphCxSpFirst&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.25in; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Sample output:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.25in; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;A0&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.25in; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;B0&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.25in; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;A1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.25in; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;B1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.25in; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;A2&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.25in; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;B2&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.25in; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;A3&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.25in; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;B3&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.25in; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;A4&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.25in; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;B4&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.25in; mso-add-space: auto" class=MsoListParagraphCxSpLast&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;Note: There is a possibility that the order may be swapped, where B gets the lock before A; the locks are handed out on a first-come, first-serve basis, it’s a race to try and get the lock at the beginning. One way of guaranteeing consistency is using events.&lt;/SPAN&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9563099" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/concurrency/default.aspx">concurrency</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Concurrency+Runtime/default.aspx">Concurrency Runtime</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Parallel+Pattern+Library/default.aspx">Parallel Pattern Library</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Asynchronous+Agents/default.aspx">Asynchronous Agents</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_0x/default.aspx">C++0x</category></item><item><title>On Channel9: a chat with members from the Visual C++ and Concurrency Runtime teams</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/01/13/on-channel9-a-chat-with-members-from-the-visual-c-and-concurrency-runtime-teams.aspx</link><pubDate>Wed, 14 Jan 2009 04:36:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9317752</guid><dc:creator>rickmolloy</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9317752.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9317752</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9317752</wfw:comment><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Calibri size=3&gt;Last week, Don McCrady, Damien Watkins from the C++ team and I sat down with Charles from Channel9 and chatted about the Concurrency Runtime, new C++ work in Visual Studio 2010 and how our teams are working together.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Calibri size=3&gt;As Charles pointed out, we also touched briefly upon new features in the C++0x standard that haven’t been discussed before.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&lt;/FONT&gt;&lt;/o:p&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;Here's the link:&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;A href="http://channel9.msdn.com/shows/Going+Deep/Parallel-Computing-in-Native-Code-New-Trends-and-Old-Friends/"&gt;&lt;FONT face=Calibri size=3&gt;http://channel9.msdn.com/shows/Going+Deep/Parallel-Computing-in-Native-Code-New-Trends-and-Old-Friends/&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Calibri size=3&gt;Enjoy and as always your feedback is very welcome,&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Calibri size=3&gt;Rick&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9317752" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Concurrency+Runtime/default.aspx">Concurrency Runtime</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Parallel+Pattern+Library/default.aspx">Parallel Pattern Library</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Asynchronous+Agents/default.aspx">Asynchronous Agents</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_0x/default.aspx">C++0x</category></item><item><title>An Introduction to Native Concurrency in Visual Studio 2010</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/01/12/an-introduction-to-native-concurrency-in-visual-studio-2010.aspx</link><pubDate>Mon, 12 Jan 2009 15:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9308034</guid><dc:creator>Atilla Gunal</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9308034.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9308034</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9308034</wfw:comment><description>&lt;DIV class=Section1&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;In this blog I will be giving an introduction to the native concurrency support in Visual Studio 2010. My motivation is that an architectural understanding of the features will enable the reader to make the most of the underlying infrastructure. In future blogs, I will go deeper into each sub topic.&lt;?xml:namespace prefix = o /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;The Goal&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;The ultimate goal of the native concurrency is to provide tools to the developers that will enable them to introduce scalable and maintainable parallelism into their applications.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;One side of the goal is to inject efficient parallelism as easy as writing the following:&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;parallel_for(0, 10, [=](int i){ foo(i); } );&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;FONT size=3&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;where&amp;nbsp;&lt;FONT face="Courier New"&gt;foo()&lt;/FONT&gt;&amp;nbsp;will be evaluated in parallel by the runtime. The other side is to enable productivity via the provided programming models.&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;The Architecture of Native Concurrency in Visual Studio 2010&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;/SPAN&gt;&lt;/B&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;Here’s a picture of the major components in the native concurrency development stack. I’d like to go through each of them and the interactions in between.&lt;/SPAN&gt;&lt;o:p&gt;&lt;B&gt;&amp;nbsp;&lt;/B&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-ALIGN: right; MARGIN: 0in 0in 0pt" class=MsoPlainText align=right&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;IMG style="WIDTH: 296px; HEIGHT: 270px" title="Native Concurrency Development Stack" alt="Native Concurrency Development Stack" align=middle src="http://blogs.msdn.com/photos/atilla_gunal/images/9307975/original.aspx" width=296 height=270 mce_src="http://blogs.msdn.com/photos/atilla_gunal/images/9307975/original.aspx"&gt;&lt;BR style="PAGE-BREAK-BEFORE: auto" clear=all&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV class=Section2&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;?xml:namespace prefix = v /&gt;&lt;v:shapetype id=_x0000_t75 coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"&gt;&lt;v:stroke joinstyle="miter"&gt;&lt;/v:stroke&gt;&lt;v:formulas&gt;&lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @0 1 0"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum 0 0 @1"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @2 1 2"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @3 21600 pixelWidth"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @3 21600 pixelHeight"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @0 0 1"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @6 1 2"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @7 21600 pixelWidth"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @8 21600 0"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @7 21600 pixelHeight"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @10 21600 0"&gt;&lt;/v:f&gt;&lt;/v:formulas&gt;&lt;v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"&gt;&lt;/v:path&gt;&lt;o:lock v:ext="edit" aspectratio="t"&gt;&lt;/o:lock&gt;&lt;/v:shapetype&gt;&lt;v:shape style="Z-INDEX: 1; POSITION: absolute; MARGIN-TOP: 5.7pt; WIDTH: 202.1pt; HEIGHT: 200.65pt; VISIBILITY: visible; MARGIN-LEFT: 265.9pt" id=Object_x0020_1 o:spid="_x0000_s1026" type="#_x0000_t75" o:gfxdata="UEsDBBQABgAIAAAAIQC75UiUBQEAAB4CAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbKSRvU7DMBSF&amp;#13;&amp;#10;dyTewfKKEqcMCKEmHfgZgaE8wMW+SSwc27JvS/v23KTJgkoXFsu+P+c7Ol5vDoMTe0zZBl/LVVlJ&amp;#13;&amp;#10;gV4HY31Xy4/tS3EvRSbwBlzwWMsjZrlprq/W22PELHjb51r2RPFBqax7HCCXIaLnThvSAMTP1KkI&amp;#13;&amp;#10;+gs6VLdVdad08ISeCho1ZLN+whZ2jsTzgcsnJwldluLxNDiyagkxOquB2Knae/OLUsyEkjenmdzb&amp;#13;&amp;#10;mG/YhlRnCWPnb8C898bRJGtQvEOiVxjYhtLOxs8AySiT4JuDystlVV4WPeM6tK3VaILeDZxIOSsu&amp;#13;&amp;#10;ti/jidNGNZ3/J08yC1dNv9v8AAAA//8DAFBLAwQUAAYACAAAACEArTA/8cEAAAAyAQAACwAAAF9y&amp;#13;&amp;#10;ZWxzLy5yZWxzhI/NCsIwEITvgu8Q9m7TehCRpr2I4FX0AdZk2wbbJGTj39ubi6AgeJtl2G9m6vYx&amp;#13;&amp;#10;jeJGka13CqqiBEFOe2Ndr+B03C3WIDihMzh6RwqexNA281l9oBFTfuLBBhaZ4ljBkFLYSMl6oAm5&amp;#13;&amp;#10;8IFcdjofJ0z5jL0MqC/Yk1yW5UrGTwY0X0yxNwri3lQgjs+Qk/+zfddZTVuvrxO59CNCmoj3vCwj&amp;#13;&amp;#10;MfaUFOjRhrPHaN4Wv0VV5OYgm1p+LW1eAAAA//8DAFBLAwQUAAYACAAAACEAqMN2nGILAAAKhwAA&amp;#13;&amp;#10;HwAAAGNsaXBib2FyZC9kcmF3aW5ncy9kcmF3aW5nMS54bWzsXdtu20gSfV9g/4Hg6yJj3kkZIw8S&amp;#13;&amp;#10;z0z2wbNj2Mm+d6iWRIQihSblyPv1W9UXXnQJLduyRpNCAEcSyWbzsNjsc7r69M+/rBe59cBFlZXF&amp;#13;&amp;#10;2HZ/cmyLF2k5yYrZ2P786fd3iW1VNSsmLC8LPrYfeWX/cvXPf/zMLmeCLedZakEJRXXJxva8rpeX&amp;#13;&amp;#10;FxdVOucLVv1ULnkB26alWLAavorZxUSwb1DyIr/wHCe6WLCssK/aon5lNbNWIntGUXmZfuWTa1Y8&amp;#13;&amp;#10;sAqKzNPL7i+6jnn68pLZZfHwUSzvl7cCa57+5+FWWNlkbANyBVsARPaF3qB3g68XG0fN2gLWU7HA&amp;#13;&amp;#10;/cvp1FrLUh7xryyDr2srhR+DYBQmDpwghW3mizrL/E91XODDP9wF9nA9dwT46nrMfxsoBSqnKgEf&amp;#13;&amp;#10;OhWTH7Fme6438MwFfxTlamkF7osufO8FnBSEdF3cLxUI1/hx86ZHBoP7WrBsNq+t67IoeFqXwgob&amp;#13;&amp;#10;PPShJhA6JVW6xI0ogPvtO+ZuJkkSmrtpwPCTJMJbLCPC9Xx5ruZGssulqOqPvFxY+GFs51nB5YPG&amp;#13;&amp;#10;Hm6qWtXD7IJXlxf4F3/5lVVz64HlY3sCn/AKoFTcDP+Zylb1Y87VYXd8CsEPIerK4uWjz69zoYpg&amp;#13;&amp;#10;acqLWsaFLAX2xsOmWZ43BzrDB+r98VA+nQK4hxzcHCHPXBbtwYusKMWus9drU+Wp2l9dvbpquJAm&amp;#13;&amp;#10;KCodGttxEZu4uIPqsmKWcytqwgF3N7FgDjXYbgRCGLiOvM+bj3UTCI6XjELTNLhBEsX6ppmSzH3W&amp;#13;&amp;#10;oSCgQt8LharMs8nvcIcQr437Wa89eWi+WvxRTtQ9htqZ4ISfsTWS0QPNlfoZ4wZfCBgVCsf2BJ2Y&amp;#13;&amp;#10;qtfqOavXH8rJI577C/wPTauo8+sSwhEukRXpvBRjO62FwjKv6nsTixM+vVVPJ3y6gwNzgH1s8+Ld&amp;#13;&amp;#10;53uNSLtL/pC7cBOsBRM3quh8Bq+/3LZgn0/sy/3/xvbIDWSDChWQu3B2U3wQXzHUoew6K/RXqNgc&amp;#13;&amp;#10;TgWvtdtVkcLDph4FXYsKSnJl2/2VC3zD4t2U0LYwdBBS4OXNM9O7G/KsVv245FOWwovmX4viXV4r&amp;#13;&amp;#10;KDjb2MCZ2pBWGxvSqoUDcFIPuMID6wXQeC00QRjL8GM/PD4IisbHb/ExQUL4ICgan6DFx/VjN8L3&amp;#13;&amp;#10;FAGEqGiAwg5AiZfI5oEAQlQ0QFELkOclEEAUQdAuIyoaoLgDUBz41EbLFxeiogFKWoAQHfkmp0cM&amp;#13;&amp;#10;UdEAjToARWFMjbSMIERF9Yg6XUvZy0e4VAA13U8JpdjoalqTTNSSwlvVor7OOYNe33CXr+UcnS4f&amp;#13;&amp;#10;9I+heLxh9dXnigvr/XKZZyl0PsuispCS1bKyqiK431vV5sK6yb4IJjJebVSDF5NbJhj0LHs98BYW&amp;#13;&amp;#10;rGbnGrc6v/uQaAuW1ww3Ba+/oQurit8vkW0pZmX4xC6uqkhMw0r6XFVWb84mXP0MzHsPj8mLXXT2&amp;#13;&amp;#10;CTz4relsyyZ201nFYvdzWVAAlbDVclnJMaX4hfz1GVzWCyIfuz1wKJB6LVAB1U1ifNWjzOWHIbZJ&amp;#13;&amp;#10;quxncVlil7tZfBsPvceQ2KVWrU6BD7FLrWfsUSeIXRrBZw9AxC4HACJ2OQAQscsBgIhdDgBE7HIA&amp;#13;&amp;#10;oKOxS9mNrq/ez2C47WBCprrYxKdgYPJJw4Nt//B5fGq0zacSRYQgmeAAPhUHkZJtgC3t5FOj2A3N&amp;#13;&amp;#10;0CDRKTl2R4N1P8RgJtEpolO9YfJDR8OJTg10ZYhODQBEdGoAIKJTAwARnRoA6Nh06vb25tDBLeJS&amp;#13;&amp;#10;mF+Jgzpvw6Vc6NBvDk6NnkOmuomWfhQHoe/3B6f81020pMEpGpw6l9RQYlPEpohNYcr3Rir1qyVf&amp;#13;&amp;#10;E5sa6OoRmxoAiNjUAEDEpgYAOjabuodZQJNVzgVxKjNp7glz354xfe2l41MuTHDa5FTAs+QY42Ej&amp;#13;&amp;#10;VF1SFfhJGBOpsnFCG80no1R8IlVEqohUEak6YdIxkaqBLjGRqgGAiFQNAHRsUnXHq3IlUm79wQo2&amp;#13;&amp;#10;I27Vunuckls1BiHFQ8frpbUKcrdtY94LUX7rmMe4W+4xcmJaDeVJtyEc+JLGK54epiomzSbgb3KT&amp;#13;&amp;#10;mT0FJ26qAeNOvUpVcsKjcgCyRAn2FSHMlcU5b3g+bUoUxXEUOjAPDDINA8+Pw0QnLJqZW94o8oHb&amp;#13;&amp;#10;KTcad2TsU/ZM26q0V05jlaMmzX3Xm2bO2eS3YiIF2LHNEC114TXL8h0b4DrJtQYHGQ9xrXF32NZA&amp;#13;&amp;#10;rL6Q+YdgZeQemfkPTSkl3xryrfkxfX1IZyCdgXQG0hlIZ/jreq+RzjBAo0lnGADoaDqDZJ3fsSrc&amp;#13;&amp;#10;59bS+Nb8ueQCW9+Zdf9Y1Xxx6OjvcytAdjGI9NGGj9MBY1y3cY1pnHG3JI7WRaaRJ5CwbukYOyQO&amp;#13;&amp;#10;IKqvLHFAzu/IgamZIHGETuj4kea9RuIIRuDJayQOLYAAwCRxqHTvJtDMfZHPrTF+7VssqST55gjc&amp;#13;&amp;#10;82nZ4m1js3vmbROUzYee1tUR4Jo5uE10NmKUBaFrFA8dl6rCvbK6uhlegFbKusbNoeOGUbiZRk7G&amp;#13;&amp;#10;zWgXfRx19snxsd/symsmFHyCJ/9Dubbc/nwCCy3HpOG1iQqcsi2jvSOldkMixIYDFF9papW4aEUo&amp;#13;&amp;#10;48u0LLGfRFFgrLzjMARndVX2nsZlyMK5KNG/WRVh4tT4obWGadpfGbz/QfTFv7b1DRz9x3YBRv8y&amp;#13;&amp;#10;TeVa+S6ra3u/qqFY7a6mjsUNf1cL5jaUyCRrtxW4EfnfDp9zkrJOET++boDAKvavb8F8CoDOalb3&amp;#13;&amp;#10;KQA6q3kIpwDorFJmTgHQWUlZpwDorKSsUwC0X8pSNsd7jYV7fsuyh11fAatLV0LAklaPPeEJmLty&amp;#13;&amp;#10;dcY+7DPKvVsVdbbgvTJBbRnyPlZ98idZbeHYvaziEJf1QJRQ6foNl91UWjytoHQTQbpKi1FTdggt&amp;#13;&amp;#10;Js3k1XJJwpETBLh2FLpWRWEAyQF9OuSBWXsA6otKJiGlRfpcv7VndPvgv1Bp8ZrJJE10tkoLkG35&amp;#13;&amp;#10;nLZxqR6QQ5UWP/AwQ6kfR7REllZIJX8/lRL3HaWlWT/OKC0QKyYcUFM5XGnproE3SuRSS7JAo7S4&amp;#13;&amp;#10;qMhFRsQNnFGo5Ln9Oi5JLcdf7apta95OSsDVv6R8dQarXZ0CH5Ja/kZZQ6cIIJJaBkbsSWoZAIik&amp;#13;&amp;#10;lgGASGoZAIiklgGAXlVquRUlrAi+gFV1Z/2lqV6qtcBSszzvu5r3ijyJ6uIP57f4W/ktA+y2P//G&amp;#13;&amp;#10;mubZ8t8ybR8//Rc/YZdVZxqEoRfgstBSR3Fg9exQj1MbspP4iVwWEBdTcklGOW8Zxd9OWNkU+SAi&amp;#13;&amp;#10;DXt+WtrKQeEWhw7kR6ksBs8J3RGFm3wa96wip570s1XtgiYLplHttsKtTYs5QrhB6xZ6I0iKwaQZ&amp;#13;&amp;#10;L0jAO6av7lHrxsBGhqUprPhhMjEOCbf/AwAA//+sUsluwjAQ/RXLP0CApKQII1Vp1R4qhIrU+8ix&amp;#13;&amp;#10;iVXHjmwrDX9fTzaVikMPcAiTybxlFs0ocC5MWNLFfreArZBS8PAh5H4HW2kNhkSVHaO1MtZRTHte&amp;#13;&amp;#10;iVoU2pEWIkHoJvBY3xP5cNGij3hnTg3i5sC0BeaOrs8e2qOLEoymS0oM1ILRU3CgzlUgT87Zb1JY&amp;#13;&amp;#10;Y6Ir60iaoM9IdZgoBttXjH5k7qSribOB0SxN8EeJ1Kp5YzQKYfSJEdJZKUlscZMlD+ljSsmF0fUq&amp;#13;&amp;#10;zfNsM8iJLhAeC/J1vkIaHguWWZ6PQ0MhpGmcD6/C1gQDRv3YxWx/EIP23YfB9gRAsDb4rASUL6Yk&amp;#13;&amp;#10;4dLEOQC2P1gIoPSND3FlCIx/U9fj4DE/724Q/rO368X31ehAKq1nYHJr4dfAsR6h8/EMF/MP8Izo&amp;#13;&amp;#10;le95bnEiZ9fg4S0032rLv0RZgGnB99M6O2gqxZ8hwO/3/Q8AAAD//wMAUEsDBBQABgAIAAAAIQDh&amp;#13;&amp;#10;UTcfzwYAAOYbAAAaAAAAY2xpcGJvYXJkL3RoZW1lL3RoZW1lMS54bWzsWc1v3EQUvyPxP4x8b7Pf&amp;#13;&amp;#10;zUbdVNnNbgNt2ijZFvU4a8/a04w91sxs0r2h9oiEhCiIA5W4cUBApVbiUv6aQBEUqf8Cb2Zsryfr&amp;#13;&amp;#10;kLSNoILmkLWff/O+35uvy1fuxQwdECEpT3pe/WLNQyTxeUCTsOfdGo8urHpIKpwEmPGE9Lw5kd6V&amp;#13;&amp;#10;9fffu4zXfEbTCcciGEckJggYJXIN97xIqXRtZUX6QMbyIk9JAt+mXMRYwasIVwKBD0FAzFYatVpn&amp;#13;&amp;#10;JcY08daBo9KMhgz+JUpqgs/EnmZDUIJjkH5zOqU+Mdhgv64Rci4HTKADzHoe8Az44ZjcUx5iWCr4&amp;#13;&amp;#10;0PNq5s9bWb+8gteyQUydMLY0bmT+snHZgGC/YWSKcFIIrY9a3UubBX8DYGoZNxwOB8N6wc8AsO+D&amp;#13;&amp;#10;pVaXMs/WaLXez3mWQPZxmfeg1q61XHyJf3NJ526/3293M10sUwOyj60l/Gqt09poOHgDsvj2Er7V&amp;#13;&amp;#10;3xgMOg7egCy+s4QfXep2Wi7egCJGk/0ltA7oaJRxLyBTzrYq4asAX61l8AUKsqHILi1iyhN1Uq7F&amp;#13;&amp;#10;+C4XIwBoIMOKJkjNUzLFPuTkAMcTQbEWgNcILn2xJF8ukbQsJH1BU9XzPkxx4pUgL599//LZE3R0&amp;#13;&amp;#10;/+nR/Z+OHjw4uv+jZeSM2sJJWB714tvP/nz0MfrjyTcvHn5RjZdl/K8/fPLLz59XA6F8FuY9//Lx&amp;#13;&amp;#10;b08fP//q09+/e1gB3xB4UoaPaUwkukEO0S6PwTDjFVdzMhGvNmIcYVoesZGEEidYS6ngP1SRg74x&amp;#13;&amp;#10;xyyLjqNHn7gevC2gfVQBr87uOgrvRWKmaIXka1HsALc5Z30uKr1wTcsquXk8S8Jq4WJWxu1ifFAl&amp;#13;&amp;#10;e4ATJ77DWQp9M09Lx/BBRBw1dxhOFA5JQhTS3/g+IRXW3aHU8es29QWXfKrQHYr6mFa6ZEwnTjYt&amp;#13;&amp;#10;Bm3RGOIyr7IZ4u34Zvs26nNWZfUmOXCRUBWYVSg/Jsxx41U8UziuYjnGMSs7/DpWUZWSe3Phl3FD&amp;#13;&amp;#10;qSDSIWEcDQMiZdWYmwLsLQX9GoaOVRn2bTaPXaRQdL+K53XMeRm5yfcHEY7TKuweTaIy9gO5DymK&amp;#13;&amp;#10;0Q5XVfBt7laIfoc44OTEcN+mxAn36d3gFg0dlRYJor/MhI4ltGqnA8c0+bt2zCj0Y5sD59eOoQE+&amp;#13;&amp;#10;//pRRWa9rY14A+akqkrYOtZ+T8Idb7oDLgL69vfcTTxLdgik+fLE867lvmu53n++5Z5Uz2dttIve&amp;#13;&amp;#10;Cm1XrxvsotgskeMTV8hTytiemjNyXZpFsoR5IhgBUY8zO0FS7JjSCB6zvu7gQoHNGCS4+oiqaC/C&amp;#13;&amp;#10;KSyw655mEsqMdShRyiVs7Ay5krfGwyJd2W1hW28YbD+QWG3zwJKbmpzvCwo2ZrYJzeYzF9TUDM4q&amp;#13;&amp;#10;rHkpYwpmv46wulbqzNLqRjXT6hxphckQw2XTgFh4ExYgCJYt4OUO7MW1aNiYYEYC7Xc79+ZhMVE4&amp;#13;&amp;#10;zxDJCAcki5G2ezlGdROkPFfMSQDkTkWM9CbvFK+VpHU12zeQdpYglcW1ThCXR+9NopRn8CJKum6P&amp;#13;&amp;#10;lSNLysXJEnTY87rtRttDPk573hT2tPAYpxB1qdd8mIVwGuQrYdP+1GI2Vb6IZjc3zC2COhxTWL8v&amp;#13;&amp;#10;Gez0gVRItYllZFPDfMpSgCVaktW/0Qa3npcBNtNfQ4vmKiTDv6YF+NENLZlOia/KwS5RtO/sa9ZK&amp;#13;&amp;#10;+UwRsRcFh2jCZmIXQ/h1qoI9AZVwNGE6gn6BczTtbfPJbc5Z0ZVPrwzO0jFLI5y1W12ieSVbuKnj&amp;#13;&amp;#10;QgfzVlIPbKvU3Rj36qaYkj8nU8pp/D8zRc8ncFLQDHQEfDiUFRjpeu15XKiIQxdKI+qPBCwcTO+A&amp;#13;&amp;#10;bIGzWPgMSQUnyOZXkAP9a2vO8jBlDRs+tUtDJCjMRyoShOxAWzLZdwqzejZ3WZYsY2QyqqSuTK3a&amp;#13;&amp;#10;E3JA2Fj3wI6e2z0UQaqbbpK1AYM7nn/ue1ZBk1Avcsr15vSQYu61NfBPr3xsMYNRbh82C5rc/4WK&amp;#13;&amp;#10;FbOqHW+G53Nv2RD9YbHMauVVAcJKU0E3K/vXVOEVp1rbsZYsbrRz5SCKyxYDsVgQpXDeg/Q/mP+o&amp;#13;&amp;#10;8Jm9bdAT6pjvQm9FcNGgmUHaQFZfsAsPpBukJU5g4WSJNpk0K+vabOmkvZZP1ue80i3kHnO21uws&amp;#13;&amp;#10;8X5FZxeLM1ecU4vn6ezMw46vLe1EV0Nkj5cokKb5RsYEpurWaRunaBLWex7c/ECg78ET3B15QGto&amp;#13;&amp;#10;WkPT4AkuhGCxZG9xel72kFPgu6UUmGZOaeaYVk5p5ZR2ToHFWXZfklM60Kn0FQdcsekfD+W3GbCC&amp;#13;&amp;#10;y24/8qbqXM2t/wUAAP//AwBQSwMEFAAGAAgAAAAhAJxmRkG7AAAAJAEAACoAAABjbGlwYm9hcmQv&amp;#13;&amp;#10;ZHJhd2luZ3MvX3JlbHMvZHJhd2luZzEueG1sLnJlbHOEj80KwjAQhO+C7xD2btJ6EJEmvYjQq9QH&amp;#13;&amp;#10;CMk2LTY/JFHs2xvoRUHwsjCz7DezTfuyM3liTJN3HGpaAUGnvJ6c4XDrL7sjkJSl03L2DjksmKAV&amp;#13;&amp;#10;201zxVnmcpTGKSRSKC5xGHMOJ8aSGtHKRH1AVzaDj1bmIqNhQaq7NMj2VXVg8ZMB4otJOs0hdroG&amp;#13;&amp;#10;0i+hJP9n+2GYFJ69elh0+UcEy6UXFqCMBjMHSldnnTUtXYGJhn39Jt4AAAD//wMAUEsBAi0AFAAG&amp;#13;&amp;#10;AAgAAAAhALvlSJQFAQAAHgIAABMAAAAAAAAAAAAAAAAAAAAAAFtDb250ZW50X1R5cGVzXS54bWxQ&amp;#13;&amp;#10;SwECLQAUAAYACAAAACEArTA/8cEAAAAyAQAACwAAAAAAAAAAAAAAAAA2AQAAX3JlbHMvLnJlbHNQ&amp;#13;&amp;#10;SwECLQAUAAYACAAAACEAqMN2nGILAAAKhwAAHwAAAAAAAAAAAAAAAAAgAgAAY2xpcGJvYXJkL2Ry&amp;#13;&amp;#10;YXdpbmdzL2RyYXdpbmcxLnhtbFBLAQItABQABgAIAAAAIQDhUTcfzwYAAOYbAAAaAAAAAAAAAAAA&amp;#13;&amp;#10;AAAAAL8NAABjbGlwYm9hcmQvdGhlbWUvdGhlbWUxLnhtbFBLAQItABQABgAIAAAAIQCcZkZBuwAA&amp;#13;&amp;#10;ACQBAAAqAAAAAAAAAAAAAAAAAMYUAABjbGlwYm9hcmQvZHJhd2luZ3MvX3JlbHMvZHJhd2luZzEu&amp;#13;&amp;#10;eG1sLnJlbHNQSwUGAAAAAAUABQBnAQAAyRUAAAAA"&gt;&lt;v:imagedata o:title="" mce_tsrc="file:///C:\Users\atgunal\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png"&gt;&lt;/v:imagedata&gt;&lt;o:lock v:ext="edit" aspectratio="f"&gt;&lt;/o:lock&gt;&lt;?xml:namespace prefix = w /&gt;&lt;w:wrap type="square"&gt;&lt;/w:wrap&gt;&lt;/v:shape&gt;&lt;I&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;Resource Manager (RM)&lt;/SPAN&gt;&lt;/I&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt; &lt;I&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;As the name of the component suggests, the main responsibility of the RM is to manage the resources, where the resources here are the processor cores of the system. These resources are requested by the scheduler(s) to execute parallel work and are then distributed by the RM to the scheduler(s).&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;In order to accomplish the distribution, the RM captures the machine topology (i.e. number of processor cores and the closeness of the processor cores to each other) at its creation time. As the schedulers are created, it takes into account various factors to make the allocation including:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.75in" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;SPAN&gt;i-&lt;SPAN style="FONT: 7pt 'Times New Roman'; font-size-adjust: none; font-stretch: normal"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;Minimum and maximum number of cores requested by each scheduler &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.75in" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;SPAN&gt;ii-&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;Scheduler priority &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.75in" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;SPAN&gt;iii- &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;Utilization of allocated processor cores per scheduler&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.75in" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;SPAN&gt;iv-&lt;SPAN style="FONT: 7pt 'Times New Roman'; font-size-adjust: none; font-stretch: normal"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;Closeness of the allocated cores of each scheduler&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.75in" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;(i.e. on a &lt;/SPAN&gt;&lt;A href="http://en.wikipedia.org/wiki/Non-Uniform_Memory_Access"&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;NUMA Architecture&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt; RM will try to allocate cores as close as possible. In other words, RM will span the allocation to a minimum number of NUMA nodes)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.75in" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;RM will not only allocate resources at the scheduler's creation time but also continue to monitor all schedulers to maximize the utilization of resources by taking from the ones that don't utilize and by giving to the ones that are in need.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;Users that are willing to implement their own scheduler will mostly use this interface of the runtime.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;For more information on concurrency runtime's resource manager please&amp;nbsp;refer to the following blog posts:&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2009/03/10/resource-management-in-the-concurrency-runtime-part-1.aspx" mce_href="http://blogs.msdn.com/nativeconcurrency/archive/2009/03/10/resource-management-in-the-concurrency-runtime-part-1.aspx"&gt;Resource Management in Concurrency Runtime - Part 1&lt;/A&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2009/07/21/resource-management-in-concurrency-runtime-part-2.aspx" mce_href="http://blogs.msdn.com/nativeconcurrency/archive/2009/07/21/resource-management-in-concurrency-runtime-part-2.aspx"&gt;Resource Management in Concurrency Runtime - Part&amp;nbsp;2&lt;/A&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2009/11/13/resource-management-in-concurrency-runtime-part-3.aspx" mce_href="http://blogs.msdn.com/nativeconcurrency/archive/2009/11/13/resource-management-in-concurrency-runtime-part-3.aspx"&gt;Resource Management in Concurrency Runtime - Part 3&lt;/A&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;I&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;Scheduler&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;Each parallel application consists of multiple tasks to be executed. As an example for the code given above; &lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;foo(0)&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;, &lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;foo(1)&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;, ..., &lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;foo(9)&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt; can be considered as tasks to be executed in parallel. It is critical to have a component to have this set of work distributed to the processor cores available for execution in an efficient way. Within the Concurrency Runtime this is responsibility of the Scheduler.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;The Scheduler, despite having a predefined default behavior, can be customized through a set of policies such as: the number of resources it will use, the number of OS threads mapped to its allocated resources, its resource allocation priority, and either it should give priority to execute tasks to increase cache hits or improve fairness across tasks.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;An important aspect of the Scheduler is that it is cooperative in the sense that it will not preempt a running task until it finishes execution or that task cooperatively yields its execution on behalf of other tasks. This is particularly important since it avoids context switches and cache being thrashed due to randomization introduced by preemption.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;Users that are willing to implement their own&amp;nbsp;concurrent library will mostly target this interface of the runtime.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;I&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;PPL&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;PPL stands for the Parallel Pattern Library and is meant to provide a convenient interface to execute work in parallel. By using PPL, you can introduce parallelism without even having to manage a scheduler. Here are the common patterns available:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Task execution patterns:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;parallel_invoke: To execute from 2 to 10 tasks in parallel&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;parallel_for: To execute tasks in parallel over a range of integers&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;parallel_for_each: To execute tasks in parallel over a collection of items in an STL container&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Synchronization patterns:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt 6pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;reader_writer_lock: A cooperative reader-writer lock that yields to other tasks instead of preempting.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt 5.25pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;critical_section:&lt;/SPAN&gt;&lt;FONT size=3 face=Consolas&gt; &lt;/FONT&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;A cooperative mutual exclusion primitive that yields to other tasks instead of preempting.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt 5.25pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&amp;nbsp; For more information on synchronization patterns please&amp;nbsp;refer to the following blog posts:&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2009/04/22/synchronization-with-the-concurrency-runtime.aspx" mce_href="http://blogs.msdn.com/nativeconcurrency/archive/2009/04/22/synchronization-with-the-concurrency-runtime.aspx"&gt;Synchronization with the Concurrency Runtime - Part 1&lt;/A&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2009/05/14/synchronization-with-the-concurrency-runtime-part-2.aspx" mce_href="http://blogs.msdn.com/nativeconcurrency/archive/2009/05/14/synchronization-with-the-concurrency-runtime-part-2.aspx"&gt;Synchronization with the Concurrency Runtime - Part&amp;nbsp;2&lt;/A&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2009/06/04/synchronization-with-the-concurrency-runtime-part-3.aspx" mce_href="http://blogs.msdn.com/nativeconcurrency/archive/2009/06/04/synchronization-with-the-concurrency-runtime-part-3.aspx"&gt;Synchronization with the Concurrency Runtime - Part&amp;nbsp;3&lt;/A&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P style="MARGIN: 0in 0in 0pt 5.25pt" class=MsoPlainText mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt; 
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Data sharing pattern:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt 6pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;combinable: A scalable object that has a local copy for each thread where processing can be done lock free on the local copy and combined afterwards when parallel processing is done. For more info on combinable please refer to &lt;/SPAN&gt;&lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2008/09/25/avoiding-contention-using-combinable-objects.aspx"&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;this&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;Application developers will mostly use this interface to inject parallelism. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;I&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;Agents &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;We all know that building software is not trivial. Building software that has to manage concurrent access to shared state is even harder. Agents are a model for decomposing parallel applications to make them easy to design, build and maintain. With Agents, you can implement the main components of the software in isolation, communicate between them by message passing (i.e. via messaging blocks), and in each Agent introduce&amp;nbsp;concurrent computation using finer grain constructs like the PPL. For more info about using Agents and messaging bocks please refer to &lt;/SPAN&gt;&lt;A href="http://blogs.msdn.com/concurrently_speaking/archive/2008/10/31/c-agents.aspx"&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;this blog&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt; or &lt;/SPAN&gt;&lt;A href="http://channel9.msdn.com/posts/Charles/Parallel-Computing-Platform-Asynchronous-Agents-for-Native-Code/"&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;this Channel9 video&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;Here are also other interesting blogs on agents and messaging blocks:&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2009/06/03/introduction-to-asynchronous-agents-library.aspx" mce_href="http://blogs.msdn.com/nativeconcurrency/archive/2009/06/03/introduction-to-asynchronous-agents-library.aspx"&gt;Introduction to Asynchronous Agents Library&lt;/A&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;A href="http://blogs.msdn.com/nativeconcurrency/archive/2009/07/02/asynchronous-agents-library-intro-to-message-blocks.aspx" mce_href="http://blogs.msdn.com/nativeconcurrency/archive/2009/07/02/asynchronous-agents-library-intro-to-message-blocks.aspx"&gt;Asynchronous Agents Library - Intro to Message Blocks&lt;/A&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;What next?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;I hope this blog helped in a better understanding of what the Concurrency Runtime is about.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"&gt;I will continue to detail each component as I give more concrete examples while digging that particular feature. Your&amp;nbsp;comments&amp;nbsp;are&amp;nbsp;valuable for me alot so please feel free to provide feedback.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9308034" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/concurrency/default.aspx">concurrency</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Concurrency+Runtime/default.aspx">Concurrency Runtime</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Asynchronous+Agents/default.aspx">Asynchronous Agents</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Resource+Manager/default.aspx">Resource Manager</category></item><item><title>Getting the Visual Studio 2010 CTP to use more than one hardware thread: using Hyper-V and other options</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2008/11/04/getting-the-visual-studio-2010-ctp-to-use-more-than-one-hardware-thread-using-hyper-v-and-other-options.aspx</link><pubDate>Wed, 05 Nov 2008 06:36:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9043184</guid><dc:creator>rickmolloy</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9043184.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9043184</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9043184</wfw:comment><description>&lt;P&gt;Last week, we blogged about the &lt;A class="" href="https://connect.microsoft.com/VisualStudio/content/content.aspx?ContentID=9790" mce_href="https://connect.microsoft.com/VisualStudio/content/content.aspx?ContentID=9790"&gt;Visual Studio 2010 CTP&lt;/A&gt; which includes the Concurrency Runtime, the Parallel Pattern Library and the Asynchronous Agents Library which is available as&amp;nbsp;a Virtual PC image.&amp;nbsp; As the Parallel Extensions to .NET team &lt;A class="" href="http://blogs.msdn.com/pfxteam/archive/2008/11/03/9037758.aspx" mce_href="http://blogs.msdn.com/pfxteam/archive/2008/11/03/9037758.aspx"&gt;blogged&lt;/A&gt; yesterday, this is unfortunate because VPC images only have a single core and this isn't great for building parallel applications.&lt;/P&gt;
&lt;P&gt;There's a couple of options to try out the CTP and the projects built with it on something other than a single-threaded VPC image.&amp;nbsp; Note that none of these are officially tested or supported so things may not work as expected.&lt;/P&gt;
&lt;P&gt;One option which is straightforward for most C++ projects is to statically link in the Runtime Libraries in your applications and move them to another computer with more than a single CPU to test them.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;To do this open the solution explorer pane and right click on your C++ project and select properties. Under the C/C++ -&amp;gt;Code Generation property page under Runtime Library select "Multi-threaded (/MT)" for release builds and "Multi-threaded Debug (/MTd)" for debug builds.&amp;nbsp; Also note that if you're using MFC in your application on the General Property Page you'll need to change the "Use of MFC" setting to something other than "Use MFC in a Shared DLL."&lt;/P&gt;
&lt;P&gt;Another option is to convert the Virtual PC image to a Hyper-V image which will allow you to see up to 4 hardware threads if they are available on your system. Grant Holliday has a &lt;A class="" href="http://blogs.msdn.com/granth/archive/2008/11/03/converting-vs2010-ctp-to-hyper-v.aspx" mce_href="http://blogs.msdn.com/granth/archive/2008/11/03/converting-vs2010-ctp-to-hyper-v.aspx"&gt;guide on his blog &lt;/A&gt;for doing this.&lt;/P&gt;
&lt;P&gt;An advantage to statically linking your application is you can run it at full speed outside of the VPC and install is straightforward; conversely an advantage to converting your VPC image to a Hyper-V image is that you can try the&amp;nbsp;Parallel Debugger&amp;nbsp;windows in the&amp;nbsp;Visual Studio debugger.&lt;/P&gt;
&lt;P&gt;As I said neither of these options&amp;nbsp;is supported, but I do hope that they can help you&amp;nbsp;make it easier to explore the Concurrency Runtime, Parallel Pattern Library and Asynchronous Agents&amp;nbsp;Library.&lt;/P&gt;
&lt;P&gt;-Rick&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9043184" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/concurrency/default.aspx">concurrency</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Concurrency+Runtime/default.aspx">Concurrency Runtime</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Parallel+Pattern+Library/default.aspx">Parallel Pattern Library</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/Asynchronous+Agents/default.aspx">Asynchronous Agents</category></item></channel></rss>