multithreading - C# Threading and Queues -


This is not about the different methods used to best utilize the queues, I have felt like this that I do not understand.

  Zero runner () {// member variable qi = q Synchronize (new queue ()); While (true) {if (0  

This is run in a thread:

  var t = new thread (runner); TIsbackground = true; T.Start ();  

Other incidents "enque" ing and where I have seen, is in the time period, the deku will actually throw an exception in the invalid operation, it should be impossible to see the queue empty. How does the count guarantee that there is something else, and I do not think that anything else is "Dequeue" ing.

Question (s):

  1. Is it possible that encapses actually increase the count on the queue (whatever it means ...)?
  2. Is it possible that the thread is being restarted in any way (ending, resetting ... ..) in Dequeue statement, but immediately after the removal of an item immediately after?
  3. Editing (Explanation):

    These code pieces are part of a wrapper class that implements the background assistant thread, only the single decay , And all the encapses / decues are on synchronized member variables (queue).

Using reflector, you can see whether or not the counting is increased until the item is added She goes.

As Ben says, it seems as if you have many people who are saying dequeue.

You say that you are positive that nothing else is calling dequeue is that because that's because you have only one thread called dequeue? What dequeue is called elsewhere?

Edit:

I wrote a small sample code, but the problem of reproduction could not be found. It was running without any exception and was running.

Before you get errors, you might be able to share a bit more code.

  class program {static q q = q} Synchronize (new qi ()); Steady bull is running = true; Fixed Zero Main () {Thread Creator 1 = New Thread (() = & gt; {while (running) {q.Enqueue (Guid.NewGuid ()); Thread.Sleep (100);}}); Thread Generator 2 = New Thread ((=) => {while (running) {q.Enqueue (Guid.NewGuid ()); Thread.Sleep (25);}}); Thread Consumers = New Thread ((=) => ON {ON} {if (q.Count> 0) {GUID G = (GUIDE) q.Dequeue (); CONSOL.VYT (G. TOWERSTING) + "");} And {console.light (".");} Threads. Sleep (1);}}); Consumer.IsBackground = True; Consumer.start (); Producer1.Start (); Producer2.Start (); Console.ReadLine (); Current = false; }}  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -