1

Topic: Question to the guru of a multithreading

Is about such code: static void SomeMethod () {var val = new SomeClass (); Queue. Enqueue (val); Trace. WriteLine ($ "Queue: {Queue. Count}");} static readonly ConcurrentQueue <SomeClass> Queue = new ConcurrentQueue <SomeClass> (); And as a result we receive an output: Queue: 0 As such can happen? And that at me something of any idea. The method, in this case, is caused exactly once.... <<RSDN@Home 1.0.0 alpha 5 rev. 0>>

2

Re: Question to the guru of a multithreading

Hello, CoderMonkey, you wrote: CM> As such can happen? Between calls Enqueue and get_Count someone in an adjacent flow had time to devastate queue.

3

Re: Question to the guru of a multithreading

Hello, hardcase, you wrote: H> Between calls Enqueue and get_Count someone in an adjacent flow had time to devastate queue. Other variants are not present? The code is correct?... <<RSDN@Home 1.0.0 alpha 5 rev. 0>>

4

Re: Question to the guru of a multithreading

Hello, CoderMonkey, you wrote: H>> Between calls Enqueue and get_Count someone in an adjacent flow had time to devastate queue. CM> other variants are not present? The code is correct? Well at an interior of this most ConcurrentQueue to look. The counter can there is somehow original is enumerated. Try to cause IsEmpty, to look that it produces.

5

Re: Question to the guru of a multithreading

Hello, CoderMonkey, you wrote: CM> As such can happen? And that at me something of any idea. The method, in this case, is caused exactly once. https://dotnetfiddle.net/1sImZf All works as expected. Try static readonly ConcurrentQueue <SomeClass> InternalQueue = new ConcurrentQueue <SomeClass> (); static readonly ConcurrentQueue <SomeClass> Queue {get {return InternalQueue;}} Also hang up brekpojnt/broad gulls on Queue.get And at once you will see who hinders you to live.

6

Re: Question to the guru of a multithreading

Hello, Glory, you wrote: Well at an interior of this most ConcurrentQueue to look. https://github.com/dotnet/coreclr/blob/ … ntQueue.cs