title: Using CList in a multithreaded environment
body: <p>I am using a CList in a multithreaded environment and I keep having problem with the GetHead method. I have one thread that add data to the list, and an other thread who read and remove data from the list.
  Here is the reading part :</p>
  
  <pre><code> value_type get_next()  
          {
            T t;
            if(!queue.IsEmpty()) {
               t = queue.GetHead();
            }
            return t;  //If the queue is empty we return an empty element
          }
  </code></pre>
  
  <p>Here is the inserting part :</p>
  
  <pre><code> inline void insert(T &amp;_in) 
          {
            queue.AddTail(_in);
          } 
  </code></pre>
  
  <p>Here is the removing part</p>
  
  <pre><code>  inline void  pop_next()  
          {
            if(!queue.IsEmpty())  {
              queue.RemoveHead(); 
            }
          }
  </code></pre>
  
  <p>Why do I get a runtime error when I run this. It always fail at</p>
  
  <pre><code>t = queue.GetHead();
  </code></pre>
  
  <p>With this assertion :</p>
  
  <pre><code>template&lt;class TYPE, class ARG_TYPE&gt;
  AFX_INLINE TYPE&amp; CList&lt;TYPE, ARG_TYPE&gt;::GetHead()
      { ENSURE(m_pNodeHead != NULL);
          return m_pNodeHead-&gt;data; }
  </code></pre>
  
  <p>While the m_pNodeHead value is : </p>
  
  <blockquote>
    <ul>
    <li>pNext   0x00000000 {pNext=??? pPrev=??? data={...}
    } CList > >,ATL::CStringT > > &amp;>::CNode *</li>
    <li>pPrev   0x00000000 {pNext=??? pPrev=??? data={...}
    } CList > >,ATL::CStringT > > &amp;>::CNode *</li>
    <li>data    "" TESTSETSE    ATL::CStringT > ></li>
    </ul>
  </blockquote>