<?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 : Concurrency Runtime</title><link>http://blogs.msdn.com/nativeconcurrency/archive/tags/Concurrency+Runtime/default.aspx</link><description>Tags: Concurrency Runtime</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>Resource Management in Concurrency Runtime – Part 3</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/11/13/resource-management-in-concurrency-runtime-part-3.aspx</link><pubDate>Fri, 13 Nov 2009 20:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9922193</guid><dc:creator>Atilla Gunal</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9922193.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9922193</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9922193</wfw:comment><description>&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-bidi-font-family: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"&gt;In my previous &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;blog post&lt;/A&gt;, I talked about the dynamic migration concept of the Concurrency Runtime’s (ConcRT) Resource Manager (RM). &lt;/SPAN&gt;Today I will be demonstrating that concept in action and will focus on its performance characteristics. &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;/P&gt;
&lt;P style="LINE-HEIGHT: normal; 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;A Demonstration of Dynamic Migration&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;The scenario that we are going to use to demonstrate the resource manager’s dynamic core migration concept involves two schedulers running different kinds of workloads in phases. The schedulers will be created with default policy on an 8 core machine (MinConcurrency=1, MaxConcurrency=8). The workload of schedulers in each phase will be characterized by one of the following:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.75in; mso-list: l0 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;Both schedulers have an equal amount of work&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: -0.5in; MARGIN: 0in 0in 0pt 0.75in; mso-list: l0 level1 lfo2; 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;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&gt;&lt;FONT face=Calibri&gt;One scheduler has work, the other one has no work&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: -0.5in; MARGIN: 0in 0in 10pt 0.75in; mso-list: l0 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;iii)&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; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;One scheduler has more work than the other scheduler&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Here are the phases and the recorded performance of the Resource Manager in detail:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;o:p&gt;&lt;IMG style="WIDTH: 540px; HEIGHT: 296px" title="Depicting Dynamic Migration" alt="Depicting Dynamic Migration" src="http://blogs.msdn.com/photos/atilla_gunal/images/9922179/original.aspx" width=576 height=299 mce_src="http://blogs.msdn.com/photos/atilla_gunal/images/9922179/original.aspx"&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-ALIGN: center; LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class=MsoNormal align=center&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /&gt;&lt;v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"&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:connecttype="rect" gradientshapeok="t" o:extrusionok="f"&gt;&lt;/v:path&gt;&lt;o:lock aspectratio="t" v:ext="edit"&gt;&lt;/o:lock&gt;&lt;/v:shapetype&gt;&lt;v:shape style="WIDTH: 382.5pt; HEIGHT: 191.25pt; VISIBILITY: visible; mso-wrap-style: square" id=Picture_x0020_9 type="#_x0000_t75" o:spid="_x0000_i1026"&gt;&lt;v:imagedata o:title="" src="file:///C:\Users\atgunal\AppData\Local\Temp\msohtmlclip1\01\clip_image001.wmz"&gt;&lt;/v:imagedata&gt;&lt;/v:shape&gt;&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;Phase1:&lt;/B&gt; In this phase both schedulers have equal amount of work. No dynamic migration happens and schedulers keep their proportionally allocated resources. Note that both schedulers have 4 resources.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;Phase2:&lt;/B&gt; Only Scheduler1 has work here. This phase starts at 2.246s; RM reacts at 2.309s by allocating all resources to Scheduler1. Note that Scheduler1 has 8 resources of which one is shared with Scheduler2. That is because resource manager cannot take away cores below the MinConcurrency value and has to have at least 1 core assigned to Scheduler1. However, Scheduler1 has no work and the resource is idle therefore Scheduler2 makes use of it without interruption.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;Phase3:&lt;/B&gt; This is similar to Phase2, this time only Scheduler2 has work. The phase starts at 4.508s; RM reacts at 4.602s by allocating all resources to Scheduler2.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;Phase4:&lt;/B&gt; Here both schedulers have work but Scheduler1’s work is more than Scheduler2’s. The phase starts at 6.833s; RM first balances resource usage among schedulers at 6.911s taking into account the workload of each. This continues until Scheduler2 completes all of its work. At 8.112s all resources are allocated back to the Scheduler1.&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/FONT&gt;&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;Focusing on Dynamic Migration Reaction Time&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&gt;&lt;FONT face=Calibri&gt;In order to give more details on the dynamic migration reaction time, a zoomed in view of Phase4 will be examined.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;o:p&gt;&lt;IMG style="WIDTH: 514px; HEIGHT: 308px" title="Focusing on Reaction Time" alt="Focusing on Reaction Time" src="http://blogs.msdn.com/photos/atilla_gunal/images/9922181/original.aspx" width=514 height=308 mce_src="http://blogs.msdn.com/photos/atilla_gunal/images/9922181/original.aspx"&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-ALIGN: center; MARGIN: 0in 0in 10pt" class=MsoNormal align=center&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;v:shape style="WIDTH: 283.5pt; HEIGHT: 180.75pt; VISIBILITY: visible; mso-wrap-style: square" id=Picture_x0020_8 type="#_x0000_t75" o:spid="_x0000_i1025"&gt;&lt;v:imagedata o:title="" src="file:///C:\Users\atgunal\AppData\Local\Temp\msohtmlclip1\01\clip_image002.wmz"&gt;&lt;/v:imagedata&gt;&lt;/v:shape&gt;&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Here the first core migration happens after 78ms where RM balances the resources between the two schedulers. This reaction time depends on a number of factors:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo1" class=MsoListParagraph&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; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;The statistics polling interval in resource manager&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraph&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;All core migration decisions are done after resource manager polls the schedulers. With the current implementation poll interval is 100ms, therefore the reaction time can be anywhere between 0 and 100ms.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraph&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; TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo1" class=MsoListParagraph&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; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;The statistics from the schedulers&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraph&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Statistics is the representation of scheduler workload in resource manager including task completion rate, incoming task rate and total task queue size. The faster the growth in statistics the faster the scheduler will get extra resources. This also implies that with a slower growth resource manager may delay allocation to the upcoming polls.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraph&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; TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo1" class=MsoListParagraph&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;3)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&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;The availability of resources&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraph&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Resource manager will only migrate if there is an available resource. Resources are considered available if other schedulers have declared their resources idle or have declining statistics. In other words, resource manager’s reaction will be delayed until there is an available resource.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt 0.5in" class=MsoListParagraph&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" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;After rebalancing, the statistics don’t change until 8.112s therefore resource manager continues with the current allocation. Whenever Scheduler2 completes all work, all resources are allocated back to Scheduler1. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; 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;Next Steps and Feedback&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;I would love to hear feedback regarding the blog content or areas of interest with respect to Concurrency Runtime to have a guided focus on blogging.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9922193" width="1" height="1"&gt;</description><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/Resource+Manager/default.aspx">Resource Manager</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>Resource Management in Concurrency Runtime – Part 2</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/07/21/resource-management-in-concurrency-runtime-part-2.aspx</link><pubDate>Tue, 21 Jul 2009 19:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9843562</guid><dc:creator>Atilla Gunal</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9843562.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9843562</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9843562</wfw:comment><description>&lt;P&gt;In my previous &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;blog post&lt;/A&gt;, I talked about key concepts of the Concurrency Runtime’s (ConcRT) resource manager, starting with a definition of a resource. I then explained why an application might be composed of a number of scheduler instances. Eventually I mentioned how the resource manager helps in resource allocation to the schedulers in order to improve performance and increase utilization of hardware. Specifically, the ‘initial allocation’ algorithm was mentioned, which defines the resource allocation done at the time of scheduler initialization.&lt;/P&gt;
&lt;P&gt;Today I will be talking about ‘dynamic migration’ which is another key concept of the resource manager. I will provide details on how the resource manager deals with resource utilization dynamically as the workload of schedulers change.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Dynamic Migration&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Dynamic migration can be defined as moving resources from one scheduler to another in order to improve CPU utilization. &lt;/P&gt;
&lt;P&gt;As an example, consider the scenario on an 8 way machine where there are two schedulers (let them be S1 and S2) created with MinConcurrency = 1 and MaxConcurrency = 8 (Please refer to &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;this&lt;/A&gt; for a description of the scheduler policy values that involves resource management). As mentioned as part of the initial allocation algorithm, after S1 and S2 are created the resources will be shared proportional to the MaxConcurrency and they will both have 4 resources: &lt;/P&gt;
&lt;P&gt;&lt;IMG style="WIDTH: 350px; HEIGHT: 231px" align=middle src="http://blogs.msdn.com/photos/atilla_gunal/images/9843554/original.aspx" width=350 height=231 mce_src="http://blogs.msdn.com/photos/atilla_gunal/images/9843554/original.aspx"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Until now this is all initial allocation. After this point, resource manager will start collecting information about the workload of the schedulers by polling periodically. At each poll the resource manager will capture the state of each scheduler instance with the &lt;A href="http://msdn.microsoft.com/en-us/library/dd504874(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd504874(VS.100).aspx"&gt;IScheduler::Statistics()&lt;/A&gt; method. Let me note that the time a scheduler instance registers to the resource manager, it has to provide an implementation of &lt;A href="http://msdn.microsoft.com/en-us/library/dd492439(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd492439(VS.100).aspx"&gt;IScheduler&lt;/A&gt; interface so that resource manager can call on that interface. The &lt;A href="http://msdn.microsoft.com/en-us/library/dd504874(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd504874(VS.100).aspx"&gt;IScheduler::Statistics()&lt;/A&gt; method is expected to return three measurements calculated by the scheduler instance itself:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Number of completed tasks since last statistics call &lt;/LI&gt;
&lt;LI&gt;Number of incoming tasks since last statistics call &lt;/LI&gt;
&lt;LI&gt;The total size of all work queues &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;The resource manager will keep a history of these measurements and derive a metric for scheduler workload for each scheduler. A statistically significant change in that metric (roughly speaking a positive or negative change as a factor of the standard deviation) will signify to the resource manager that the scheduler either needs one or more additional resources or can give away one or more. The bigger the change the more resources will be added or removed. &lt;/P&gt;
&lt;P&gt;After polling each scheduler, the resource manager will have a list of schedulers (L1) that can give away a number of resources and a list of schedulers (L2) that needs a number of resources. Next thing to do then for all schedulers in L1, starting from the one with the minimum resource allocation priority, is to remove extra resources and re-allocate them to the schedulers in L2 starting with the highest priority. It is important to note that if L2 is empty, then schedulers in L1 will still keep their resources. &lt;/P&gt;
&lt;P&gt;Let’s return back to the example above and assume that the resource manager has decided S1 can give away 2 resources and S2 can make use of 2 resources. The resource manager will inform S1 to give away 2 resources, oversubscribe the hardware threads with 2 more resources and inform S2 that it can now use the extra resources. It is expected that S1 will obey the protocol and release the resources as soon as possible. After this protocol completes, the allocation will be as follows: &lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG style="WIDTH: 353px; HEIGHT: 214px" src="http://blogs.msdn.com/photos/atilla_gunal/images/9843565/original.aspx" width=353 height=214 mce_src="http://blogs.msdn.com/photos/atilla_gunal/images/9843565/original.aspx"&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;More Details on Dynamic Migration &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;We covered the general idea of dynamic migration. Let us walk through some what-if scenarios.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. What happens if S1 has no work at all and S2 is still in need of resources, does S1 fall back to zero resources? &lt;/P&gt;
&lt;P&gt;As a general rule of resource allocation, the resource manager will never allocate fewer resources to a scheduler than its MinConcurrency policy value. Therefore S1 will at least have 1 resource assigned. However since there is no work for S1, S1 will put that resource into inactive mode indicating to the resource manager that the resource is idle. Knowing this, the resource manager will share the underlying hardware thread by oversubscribing and providing another resource to S2. &lt;/P&gt;
&lt;P&gt;2. What would happen if S1 shuts down and S2 is still in need of more? &lt;/P&gt;
&lt;P&gt;All resources of S1 will become available. Resources will be allocated to S2 (not more than MaxConcurrency of S2) soon after. &lt;/P&gt;
&lt;P&gt;3. On a machine with &lt;A href="http://en.wikipedia.org/wiki/Non-Uniform_Memory_Access" mce_href="http://en.wikipedia.org/wiki/Non-Uniform_Memory_Access"&gt;NUMA&lt;/A&gt; topology, is locality considered? &lt;/P&gt;
&lt;P&gt;Locality information is used after the resource manager decides which scheduler is going to give away resources and which scheduler is going to take more (note that the schedulers are selected from the L1 and L2 list with respect to their allocation priority – therefore locality is less important compared to allocation priority). Let S1 (an element of L1) have R1 resources to give away and S2 (an element of L2) be in a need of R2 resources. If R1 is greater than R2 then the subset of resources to be allocated to S2 will be selected with respect to locality. Here is an example: &lt;/P&gt;
&lt;P&gt;&lt;IMG style="WIDTH: 363px; HEIGHT: 229px" src="http://blogs.msdn.com/photos/atilla_gunal/images/9843567/original.aspx" width=363 height=229 mce_src="http://blogs.msdn.com/photos/atilla_gunal/images/9843567/original.aspx"&gt;&lt;/P&gt;
&lt;P&gt;Assume this is the allocation layout before dynamic migration where Node1 and Node2 are NUMA nodes having 4 cores each. Let S1 be in need of 2 resources and S2 be able to give away 4. The resource manger will select two resources from S1 close to the ones in S2. Since resources of S2 (Core1 and Core3) are closer to Core2 and Core4 (as cores 1 to 4 are in the same node), the resource manager will migrate Core2 and Core4 to S2. After dynamic migration this would be the layout: &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;IMG style="WIDTH: 369px; HEIGHT: 230px" src="http://blogs.msdn.com/photos/atilla_gunal/images/9843568/original.aspx" width=369 height=230 mce_src="http://blogs.msdn.com/photos/atilla_gunal/images/9843568/original.aspx"&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Next Steps and Feedback &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Next I will demonstrate dynamic migration and focus on its performance characteristics. I would love to hear feedback regarding the blog content or areas of interest with respect to Concurrency Runtime to have a guided focus on blogging. &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9843562" width="1" height="1"&gt;</description><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/Resource+Manager/default.aspx">Resource Manager</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>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>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>Resource Management in the Concurrency Runtime – Part 1</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/03/10/resource-management-in-the-concurrency-runtime-part-1.aspx</link><pubDate>Tue, 10 Mar 2009 13:03:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9468942</guid><dc:creator>Atilla Gunal</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9468942.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9468942</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9468942</wfw:comment><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;In my previous blog post, I gave an introduction to the native concurrency runtime in Visual Studio 2010. 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"&gt;&lt;FONT face=Calibri size=3&gt;this&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; post. Today, I will talk about the lowest level in that component stack: the Resource Manager (RM).&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;Resource Manager Responsibilities&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 short, there are two main responsibilities of the Resource Manager:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpFirst style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&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 face=Calibri size=3&gt;1-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&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;&lt;B style="mso-bidi-font-weight: normal"&gt;Initial Allocation:&lt;/B&gt; Allocating resources to schedulers when schedulers are created.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpLast style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&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 face=Calibri size=3&gt;2-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&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;&lt;B style="mso-bidi-font-weight: normal"&gt;Dynamic Migration:&lt;/B&gt; Constantly monitoring utilization of resources by schedulers, and dynamically migrating resources between schedulers.&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;This post will focus on the initial allocation and the dynamic migration will be detailed in my next blog 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;What is a Resource Anyway?&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;Before going into details about the “Resource Manager” for the Concurrency Runtime, let’s define what is meant by a resource in this context. A resource is the unit of the processing power of the machine which is owned by the RM and used by schedulers. A resource is abstracted in the form of a “Virtual Processor” in Concurrency Runtime. At a given time each virtual processor is associated with a thread running on a processor core (see below - Resource Boundary). The RM creates virtual processors and hands them to schedulers; meanwhile, scheduler instances use them to execute tasks in parallel. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: center" align=center&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /&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;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="FONT-SIZE: 11pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; 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-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;&lt;IMG style="WIDTH: 361px; HEIGHT: 265px" height=265 src="http://blogs.msdn.com/photos/atilla_gunal/images/9468901/original.aspx" width=361 mce_src="http://blogs.msdn.com/photos/atilla_gunal/images/9468901/original.aspx"&gt;&lt;BR style="PAGE-BREAK-BEFORE: always" clear=all&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Why do we need a Resource Manager?&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;Clearly, we wouldn’t need a Resource Manager if it was possible for a single scheduler to fit all the needs of parallel tasks. However, there are a couple of reasons why it is feasible for an app to use multiple schedulers:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpFirst style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l3 level1 lfo2"&gt;&lt;SPAN style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&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; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;I style="mso-bidi-font-style: normal"&gt;The hotter the cache, the faster the processing:&lt;/I&gt; Virtual processors have affinity to group of processor cores; the sockets or nodes. The more they do related work, the more likely they are to find that the data they need is already in the cache.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 1in; TEXT-INDENT: -0.25in; mso-list: l3 level2 lfo2; mso-add-space: auto"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Courier New'"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;o&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Assume that your app uses a bunch of libraries. It is highly probable that work performed by a given library is related. Having a scheduler per library will keep the cache warm and enable faster processing.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l3 level1 lfo2"&gt;&lt;SPAN style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&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; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;I style="mso-bidi-font-style: normal"&gt;Not all schedulers are same:&lt;/I&gt; A scheduler instance is policy driven. This means different schedulers might have different characteristics.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpLast style="MARGIN: 0in 0in 10pt 1in; TEXT-INDENT: -0.25in; mso-list: l3 level2 lfo2; mso-add-space: auto"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Courier New'"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;o&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Assume that a game engine is to be implemented. As an example, it could have an image rendering component, a sound rendering component and an object state update component. All these will execute in parallel; however, we might want state update to have a higher thread priority and would like to decouple sound processing tasks from image rendering tasks. Having multiple schedulers will enable us to customize scheduler behavior and separate task execution.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Now given that there can be multiple schedulers in a process for the reasons mentions above, let’s talk about if a resource manager was not present what would happen:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpFirst style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l1 level1 lfo3"&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 face=Calibri size=3&gt;1-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Schedulers would be free to use any resource&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpLast style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l1 level1 lfo3"&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 face=Calibri size=3&gt;2-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Schedulers would implement a way of sharing resources&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Apparently the first one would end up with a non-optimum utilization of resources; some processors cores would be over utilized and some would be underutilized due to no communication between schedulers. On the other hand, the second one would end up with a complex design contradicting with design patterns like ‘Low Coupling’ or ‘High Cohesion’ (&lt;/FONT&gt;&lt;A href="http://en.wikipedia.org/wiki/GRASP_(Object_Oriented_Design)"&gt;&lt;FONT face=Calibri color=#0000ff size=3&gt;http://en.wikipedia.org/wiki/GRASP_(Object_Oriented_Design)&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; ). Thanks to RM that it helps resources to be utilized evenly meanwhile still keeping the design of a scheduler simpler. By the way it is important to keep the design of the scheduler simpler because users can also implement a custom scheduler on top of RM (see below for more on this).&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Additionally, the scheduler implemented as part of the concurrency runtime is a general purpose scheduler; for specialty scenarios, it may be possible to implement a scheduler tuned for a particular purpose, and it’s important that such a scheduler be usable in conjunction with other work in the same process and without oversubscribing on resources. Thanks to RM again that by using its APIs custom schedulers can be built meanwhile respecting the resource usage of other schedulers in the process.&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;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/B&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;The Initial Allocation of Resources&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;Now we can describe initial allocation, one of the core functions of the Resource Manager.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;As mentioned in the Resource Manager Responsibilities paragraph, initial allocation is about providing the resources to a scheduler at its creation time. A diagram of initial allocation steps can be found below. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: center" align=center&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;&lt;IMG src="http://blogs.msdn.com/photos/atilla_gunal/images/9468935/original.aspx" mce_src="http://blogs.msdn.com/photos/atilla_gunal/images/9468935/original.aspx"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;A scheduler instance will place its request for resources by providing a set of policies to the resource manager. The resource manager will do the allocation depending on the policies and taking into account the other schedulers in the process. Eventually the resources will be provided to the scheduler in need.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;The policy values given in step-1 play an important role in how many virtual processors the scheduler will have. Let’s go through those policies that effect initial allocation:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;U&gt;MinConcurrency and MaxConcurrency:&lt;/U&gt;&lt;/B&gt; These two policies specify the concurrency level of the scheduler. The number of virtual processors allocated to the scheduler by the RM will be bounded by these policy values. Depending on the existence and policy of the other schedulers, any number of resources can be allocated in between. &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;U&gt;TargetOversubscriptionFactor:&lt;/U&gt;&lt;/B&gt; Oversubscription is defined as the number of threads associated with a particular processor core. RM will try to allocate resources up to MaxConcurrency by oversubscribing each core with the given TargetOversubscriptionFactor.&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 an example where the scheduler actually asks for minimum of 1 processor core and maximum of 2 processor cores both oversubscribed by a factor of 2. If there are no other schedulers, on a 2 core machine the allocation will be as shown below.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: center" align=center&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;U&gt;&lt;IMG style="WIDTH: 254px; HEIGHT: 224px" height=224 src="http://blogs.msdn.com/photos/atilla_gunal/images/9468938/original.aspx" width=254 mce_src="http://blogs.msdn.com/photos/atilla_gunal/images/9468938/original.aspx"&gt;&lt;/U&gt;&lt;/B&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;U&gt;ResourceAllocationPriority:&lt;/U&gt;&lt;/B&gt; RM will try to satisfy the requests of the schedulers with higher priority at the cost of lower priority schedulers. &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;Now let’s take a look at a general overview of the rules of initial allocation and some examples of it in order to understand the usage of the policy values.&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;Rules of Initial Allocation&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;Initial allocation has a set of rules that defines its behavior. I will mention those rules and then in the next paragraph will try to give examples to explain in more detail.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpFirst style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l2 level1 lfo4"&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 face=Calibri size=3&gt;1)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;RM will never allocate less resources then MinConcurrency and more resources than MaxConcurrency&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l2 level1 lfo4"&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 face=Calibri size=3&gt;2)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;RM will share cores within schedulers as minimum as possible&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l2 level1 lfo4"&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 face=Calibri size=3&gt;3)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;The resources will be allocated as close as possible. The closeness criteria here is that the processor cores in a NUMA node / processor socket are closer with respect to processor cores in other NUMA nodes / processor sockets.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l2 level1 lfo4"&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 face=Calibri size=3&gt;4)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;The resources will be proportionally distributed with respect to MaxConcurrency within the schedulers of equal priority if MaxConcurrency cannot be met.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpLast style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l2 level1 lfo4"&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 face=Calibri size=3&gt;5)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Until MaxConcurrency resources are provided to a higher priority scheduler, lower priority schedulers will be reduced to their MinConcurrency&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;Examples of Initial Allocation&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;I style="mso-bidi-font-style: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;We have mentioned that multiple schedulers may reside in a process. What if there is an existing Scheduler (S1) when a Scheduler (S2) with the same ResourceAllocationPriority requests resources?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;RM will try to avoid sharing of processor cores between S1 and S2 as much as possible. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Scenario1: If there are no resources available to satisfy S2 then a proportional allocation will be performed between all schedulers that have the same ResourceAllocationPriority (S1 and S2). Allocation is proportional to each scheduler’s policy value of MaxConcurrency. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Scenraio2: If there are N available resources such that MinConcurrency of S2 &amp;lt;= N &amp;lt;= MaxConcurrency of S2, N resources are allocated to S2, and S1 is left untouched. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&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 10pt; TEXT-ALIGN: center" align=center&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;&lt;IMG style="WIDTH: 269px; HEIGHT: 248px" height=248 src="http://blogs.msdn.com/photos/atilla_gunal/images/9468913/original.aspx" width=269 mce_src="http://blogs.msdn.com/photos/atilla_gunal/images/9468913/original.aspx"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Please note here that S1’s number of allocated cores is reduced from 4 to 2 when a scheduler with equal ResourceAllocationPriority is created. &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;SPAN style="mso-no-proof: yes"&gt;&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;&lt;IMG src="http://blogs.msdn.com/photos/atilla_gunal/images/9468922/original.aspx" mce_src="http://blogs.msdn.com/photos/atilla_gunal/images/9468922/original.aspx"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Resources of S1 is not touched and S2 gets only 3 of its requested resources when there are at least MinConcurrency number of resources available for S2. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;What if ResourceAllocationPriority of&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;S2&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;is greater than S1?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;In this case RM will lower S1 to MinConcurrency, and try to allocate N resources where MinConcurrency of S2 &amp;lt;= N &amp;lt;= MaxConcurrency to S2. If N is less than the minimum that S2 requires, RM will share processors cores with S1, to satisfy S2’s minimum request.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;What if the machine supports NUMA architecture? Is locality taken into account?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Yes, RM will try to localize the allocation as much as possible. For example, on a machine with 2 sockets and 2 processor cores in each socket, the allocations will be made within socket boundaries.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;IMG src="http://blogs.msdn.com/photos/atilla_gunal/images/9468933/original.aspx" mce_src="http://blogs.msdn.com/photos/atilla_gunal/images/9468933/original.aspx"&gt;&amp;nbsp;&lt;/I&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;I style="mso-bidi-font-style: normal"&gt;What if both S1 and S2 has MinConcurrency=Max&lt;/I&gt;Concurrency&lt;I style="mso-bidi-font-style: normal"&gt;=Number of processor cores of the machine?&lt;o:p&gt;&lt;/o:p&gt;&lt;/I&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;Since RM can’t allocate less than MinConcurrency and both schedulers have requested all cores, all the cores will be shared between S1 and S2. In general, RM will share cores in the final step of initial allocation algorithm, and share as little as possible.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;What if one of S1 shutdowns? Are the resources made available to S2?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;If S2 doesn’t have MaxConcurrency allocated at the time S1 shutdowns, dynamic migration will increase the number of resources of S2. However dynamic resource management is a whole topic unto itself, and I will write about it in my next blog. &lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9468942" width="1" height="1"&gt;</description><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/Resource+Manager/default.aspx">Resource Manager</category></item><item><title>Concurrency Runtime and Windows 7</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/02/04/concurrency-runtime-and-windows-7.aspx</link><pubDate>Thu, 05 Feb 2009 05:30:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9397325</guid><dc:creator>dmccrady</dc:creator><slash:comments>24</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9397325.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9397325</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9397325</wfw:comment><description>&lt;p&gt;Microsoft has recently released a beta for Windows 7, and a look at the official web site (&lt;a href="http://www.microsoft.com/windows/windows-7/default.aspx"&gt;http://www.microsoft.com/windows/windows-7/default.aspx&lt;/a&gt;) will show you a pretty impressive list of new features and usability enhancements. I encourage you to go look them over for yourself, but in this article I&amp;#8217;m going to focus on a couple of Win7 features that are of particular importance to achieving the most performance of your parallel programs.&lt;/p&gt;  &lt;p&gt;1. Support for more than 64 processors&lt;/p&gt;  &lt;p&gt;2. User-Mode Scheduled Threads&lt;/p&gt;  &lt;p&gt;Both of the new features I&amp;#8217;m going to talk about will be supported in the Microsoft Concurrency Runtime, which will be delivered as part of Visual Studio 10.&lt;/p&gt;  &lt;p&gt;An important note about each of these features is that they&amp;#8217;re only supported on the &lt;i&gt;64-bit&lt;/i&gt; Windows 7 platform.&lt;/p&gt;  &lt;h3&gt;More Than 64 Processors&lt;/h3&gt;  &lt;p&gt;The most straightforward of these new features is Windows 7&amp;#8217;s support for more than 64 processors. With earlier Windows OS&amp;#8217;s, even high end servers could only schedule threads among a maximum of 64 processors. Windows 7 will allow threads to run on more than 64 processors by allowing threads to be affinitized to both a processor &lt;i&gt;group&lt;/i&gt;, and a processor &lt;i&gt;index&lt;/i&gt; within that group. Each group can have up to 64 processors, and Windows 7 supports a maximum of 4 processor groups. The mechanics of this new OS support are detailed in a white paper which is available at &lt;a href="http://www.microsoft.com/whdc/system/Sysinternals/MoreThan64proc.mspx"&gt;http://www.microsoft.com/whdc/system/Sysinternals/MoreThan64proc.mspx&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;However, unless you actively modify your application to affinitize work amongst other processor groups, you&amp;#8217;ll still be stuck with a maximum of 64 processors. The good news is that if you use the Microsoft Concurrency Runtime on Windows 7, you don&amp;#8217;t need to be concerned at all with these gory details. As always, the runtime takes care of everything for you, and will automatically determine the total amount of available concurrency (e.g., total number of cores), and utilize as many as it can during any parallel computation. This is an example of what we call a &amp;#8220;light-up&amp;#8221; scenario. Compile your Concurrency Runtime-enabled application once, and you can run it on everything, from your Core2-Duo up to your monster Win7 256-core server.&lt;/p&gt;  &lt;h3&gt;User Mode Scheduling&lt;/h3&gt;  &lt;p&gt;User Mode Scheduled Threads (UMS Threads) is another Windows 7 feature that &amp;#8220;lights up&amp;#8221; in the Concurrency Runtime.&lt;/p&gt;  &lt;p&gt;As the name implies, UMS Threads are threads that are scheduled by a user-mode scheduler (like Concurrency Runtime&amp;#8217;s scheduler), instead of by the kernel. Scheduling threads in user mode has a couple of advantages:&lt;/p&gt;  &lt;p&gt;1. A UMS Thread can be scheduled without a kernel transition, which can provide a performance boost.&lt;/p&gt;  &lt;p&gt;2. Full use of the OS&amp;#8217;s quantum can be achieved if a UMS Thread blocks for any reason.&lt;/p&gt;  &lt;p&gt;To illustrate the 2&lt;sup&gt;nd&lt;/sup&gt; point, let&amp;#8217;s assume a very simple scheduler with a single work queue. In this example, I&amp;#8217;ll also assume that we have 100 tasks that can be run in parallel on 2 CPU&amp;#8217;s.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/nativeconcurrency/WindowsLiveWriter/ConcurrencyRuntimeandWindows7_10409/ConcRT%20and%20Win7%20UMS_2.jpg"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="ConcRT and Win7 UMS" src="http://blogs.msdn.com/blogfiles/nativeconcurrency/WindowsLiveWriter/ConcurrencyRuntimeandWindows7_10409/ConcRT%20and%20Win7%20UMS_thumb.jpg" width="427" height="251" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Here we&amp;#8217;ve started with 100 items in our task queue, and two threads have picked up Task 1 and Task 2 and are running them in parallel. Unfortunately, Task 2 is going to block on a critical section. Obviously, we would like the scheduler (i.e. the Concurrency Runtime) to use CPU 2 to run the other queued tasks while Task 2 is blocked. Alas, with ordinary Win32 threads, the scheduler cannot tell the difference between a task that is performing a very long computation and a task that is simply blocked in the kernel. The end result is that until Task 2 unblocks, the Concurrency Runtime will not schedule any more tasks on CPU 2. Our 2-core machine just became a 1-core machine, and in the worst case, all 99 remaining tasks will be executed serially on CPU 1.&lt;/p&gt;  &lt;p&gt;This situation can be improved somewhat by using the Concurrency Runtime&amp;#8217;s &lt;i&gt;cooperative&lt;/i&gt; synchronization primitives (critical_section, reader_writer_lock, event) instead of Win32&amp;#8217;s kernel primitives. These runtime-aware primitives will cooperatively block a thread, informing the Concurrency Runtime that other work can be run on the CPU. In the above example, Task 2 will cooperatively block, but Task 3 can be run on another thread on CPU 2. All this involves several trips through the kernel to block one thread and unblock another, but it&amp;#8217;s certainly better than wasting the CPU.&lt;/p&gt;  &lt;p&gt;The situation is improved even further on Windows 7 with UMS threads. When Task 2 blocks, the OS &lt;i&gt;gives control back&lt;/i&gt; to Concurrency Runtime. It can now make a scheduling decision and create a new thread to run Task 3 from the task queue. The new thread is scheduled in user-mode by the Concurrency Runtime, not by the OS, so the switch is very fast. Now both CPU 1 and CPU 2 can now be kept busy with the remaining 99 non-blocking tasks in the queue. When Task 2 gets unblocked, Win7 places its host thread back on a runnable list so that the Concurrency Runtime can schedule it &amp;#8211; again, from user-mode &amp;#8211; and Task 2 can be continued on any available CPU. &lt;/p&gt;  &lt;p&gt;You might say, &amp;#8220;hey my task doesn&amp;#8217;t do any kernel blocking, so does this still help me?&amp;#8221; The answer is yes. First, it&amp;#8217;s really difficult to know whether your task will block at all. If you call &amp;#8220;new&amp;#8221; or &amp;#8220;malloc&amp;#8221; you may block on a heap lock. Even if you didn&amp;#8217;t block, the operation might &lt;i&gt;page-fault&lt;/i&gt;. An I/O operation will also cause a kernel transition. All these occurrences can take significant time and can stall forward progress on the core upon which they occur. These are opportunities for the scheduler to execute additional work on the now-idle CPU. Windows 7 UMS Threads enables these opportunities, and the result is greater throughput of tasks and more efficient CPU utilization. &lt;/p&gt;  &lt;p&gt;(Some readers may have noticed a superficial similarity between UMS Threads and Win32 Fibers. The key difference is that unlike a Fiber, a UMS Thread is a real bona-fide thread, with a backing kernel thread, its own thread-local state, and the ability to run code that can call arbitrary Win32 API&amp;#8217;s. Fibers have severe restrictions on the kinds of Win32 API&amp;#8217;s they can call.)&lt;/p&gt;  &lt;p&gt;Obviously the above example is highly simplified. A UMS Thread scheduler is an extremely complex piece of software to write, and managing state when an arbitrary page fault can swap you out is challenging to say the least. However, once again users of the Concurrency Runtime don&amp;#8217;t have to be concerned with any of these gory details. Write your programs once using PPL or Agents, and your code will run using Win32 threads or UMS Threads.&lt;/p&gt;  &lt;p&gt;For more details about UMS Threads, check out &lt;a href="http://channel9.msdn.com/shows/Going+Deep/Dave-Probert-Inside-Windows-7-User-Mode-Scheduler-UMS/"&gt;Inside Windows 7 - User Mode Scheduler (UMS)&lt;/a&gt; with Windows Kernel architect Dave Probert on Channel9.&lt;/p&gt;  &lt;h3&gt;Better Together&lt;/h3&gt;  &lt;p&gt;Windows 7 by itself is a great enabler of fine grain parallelism, because of the above two specific features, as well as some other performance improvements made at the kernel level. The Concurrency Runtime helps bring the fullest potential of Windows 7 into the hands of programmers in a very simple and powerful way.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9397325" 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/Win7/default.aspx">Win7</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/UMS/default.aspx">UMS</category></item><item><title>Dave Probert ‘goes deep’ on Win7 User Mode Scheduled Threads</title><link>http://blogs.msdn.com/nativeconcurrency/archive/2009/02/02/dave-probert-goes-deep-on-win7-user-mode-scheduled-threads.aspx</link><pubDate>Mon, 02 Feb 2009 23:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9391673</guid><dc:creator>rickmolloy</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/nativeconcurrency/comments/9391673.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nativeconcurrency/commentrss.aspx?PostID=9391673</wfw:commentRss><wfw:comment>http://blogs.msdn.com/nativeconcurrency/rsscomments.aspx?PostID=9391673</wfw:comment><description>&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;Charles Torre just posted a great Channel9 session with Windows kernel architect Dave Probert on functionality&amp;nbsp;new to&amp;nbsp;Windows7: User Mode Scheduled (UMS) Threads.&amp;nbsp; Much like fibers, UMS threads enable a user mode scheduler (like the Concurrency Runtime) to have control over scheduling of threads in user mode; however unlike fibers, UMS threads keep the TEB and thread local information intact and provides notification of kernel blocking which enables more general use. &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-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;In the near future we'll be blogging here about how the Concurrency Runtime is taking advantage of UMS threads on Win7, but if you have some time to spare, check out what Dave has to say on this it's a wonderful session.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;&lt;A href="http://channel9.msdn.com/shows/Going+Deep/Dave-Probert-Inside-Windows-7-User-Mode-Scheduler-UMS/" mce_href="http://channel9.msdn.com/shows/Going+Deep/Dave-Probert-Inside-Windows-7-User-Mode-Scheduler-UMS/"&gt;http://channel9.msdn.com/shows/Going+Deep/Dave-Probert-Inside-Windows-7-User-Mode-Scheduler-UMS/&lt;/A&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;-Rick&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9391673" 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/Win7/default.aspx">Win7</category><category domain="http://blogs.msdn.com/nativeconcurrency/archive/tags/UMS/default.aspx">UMS</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></channel></rss>