Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is absolutely <em>not</em> thread-safe. From the docs of <a href="http://msdn.microsoft.com/en-us/library/7977ey2c.aspx" rel="noreferrer"><code>Queue&lt;T&gt;</code></a>.</p> <blockquote> <p>Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.</p> <p>A <code>Queue&lt;T&gt;</code> can support multiple readers concurrently, as long as the collection is not modified. Even so, enumerating through a collection is intrinsically not a thread-safe procedure. To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.</p> </blockquote> <p>Rereading your question, you seem to be confused about the phrase "static members of this type" - it's not talking about "a static Queue" as there's no such thing. An object isn't static or not - a member is. When it talks about static members it's talking about things like <code>Encoding.GetEncoding</code> (<code>Queue&lt;T&gt;</code> doesn't actually have any static members). Instance members are things like <code>Enqueue</code> and <code>Dequeue</code> - members which relate to an instance of the type rather than the type itself.</p> <p>So either you need to use a lock for each action, or if you're using .NET 4, use <a href="http://msdn.microsoft.com/en-us/library/dd267265.aspx" rel="noreferrer"><code>ConcurrentQueue&lt;T&gt;</code></a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload