[ sotsprodigy @ 25.05.2007. 14:09 ] @
Ima problem oko sinhronizacije niti pomocu monotora.Monitor mi zauzme promenljivu (objekat) ali nece da je oslobodi. Evo koda pa ako neko zna gde gresim .... private void nit1() { Control.CheckForIllegalCrossThreadCalls = false; for (; ; ) { this.proces1.SetSelected(1, true); // neksriticna sekcija Thread.Sleep(trackBar1.Value); this.proces1.SetSelected(2, true); // zakljucaj promenljivu Thread.Sleep(trackBar1.Value); if (Monitor.TryEnter(deljiva)) { Monitor.Enter(deljiva); this.proces1.SetSelected(3, true); // { Thread.Sleep(trackBar1.Value); deljiva.Enqueue(15); this.proces1.SetSelected(4, true); Thread.Sleep(trackBar1.Value); this.proces1.SetSelected(5, true); // } Thread.Sleep(trackBar1.Value); this.proces1.SetSelected(6, true); //otkljucaj promenljivu Monitor.Exit(deljiva); Monitor.Pulse(deljiva); Thread.Sleep(trackBar1.Value); } else { while (!Monitor.TryEnter(deljiva)) { }; Monitor.Enter(deljiva); this.proces1.SetSelected(3, true); // { Thread.Sleep(trackBar1.Value); deljiva.Enqueue(15); this.proces1.SetSelected(4, true); Thread.Sleep(trackBar1.Value); this.proces1.SetSelected(5, true); // } Thread.Sleep(trackBar1.Value); this.proces1.SetSelected(6, true); //otkljucaj promenljivu Monitor.Exit(deljiva); Monitor.Pulse(deljiva); Thread.Sleep(trackBar1.Value); } this.proces1.SetSelected(7, true); Thread.Sleep(trackBar1.Value); } |