Click here to Skip to main content
16,018,394 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to make setup & deploy a Pocket Pc application Pin
Jalpesh B. Patel25-Jul-07 4:21
Jalpesh B. Patel25-Jul-07 4:21 
AnswerRe: How to make setup & deploy a Pocket Pc application Pin
Jalpesh B. Patel25-Jul-07 4:25
Jalpesh B. Patel25-Jul-07 4:25 
GeneralRe: How to make setup & deploy a Pocket Pc application Pin
Raza Hussain26-Jul-07 2:00
Raza Hussain26-Jul-07 2:00 
Questionplaying video files? Pin
Tarun.Suneja25-Jul-07 4:07
Tarun.Suneja25-Jul-07 4:07 
AnswerRe: playing video files? Pin
ashukasama25-Jul-07 4:21
ashukasama25-Jul-07 4:21 
GeneralRe: playing video files? Pin
Tarun.Suneja25-Jul-07 4:37
Tarun.Suneja25-Jul-07 4:37 
GeneralRe: playing video files? Pin
ekynox25-Jul-07 4:50
ekynox25-Jul-07 4:50 
QuestionSynchronizing Mulithreaded Loops Pin
Salamandras25-Jul-07 4:05
Salamandras25-Jul-07 4:05 
Greetings
I am trying to make threads that run loops to be at the exact same step as the other threads. For example an output to the application could be the following:

Thread 1 = iteration 1
Thread 2 = iteration 1
Thread 3 = iteration 1
Thread 4 = iteration 1
Thread 1 = iteration 2
Thread 2 = iteration 2
Thread 3 = iteration 2
Thread 4 = iteration 2
and not
Thread 1 = iteration 3
Thread 2 = iteration 2
Thread 3 = iteration 1
Thread 4 = iteration 1
Thread 1 = iteration 4
Thread 2 = iteration 3
Thread 3 = iteration 2
Thread 4 = iteration 1

I am thinking of an implementation such as:
the first thread runs the iteration and waits
the second thread runs the iteration and waits...
the last thread runs the iteration and notifies all the other threads to wake (and go to the next step)
I have tried the following but it doesnt work:
<br />
CommonClass commonObject = (CommonClass)o;//a public object created in Main for all the threads to acquire lock to<br />
        for (int i = 0; i < 4; i++)<br />
        {<br />
            Console.WriteLine("Thread " + Thread.CurrentThread.Name + " is in iteration " + i);<br />
            lock (commonObject)<br />
            {<br />
                if (Interlocked.Decrement(ref threadCounter) == 1)//last thread <br />
                {<br />
                    threadCounter = 4;//reset the counter<br />
                    Monitor.PulseAll(commonObject);//notify all the other threads to wake<br />
                }<br />
                else { Monitor.Wait(commonObject); }//or wait until notified<br />
            }            <br />
        }<br />


Do you find this approach correct?
Can you please suggest feasible solution?

Thanks in advance
AnswerRe: Synchronizing Mulithreaded Loops Pin
PhilDanger25-Jul-07 4:37
PhilDanger25-Jul-07 4:37 
AnswerRe: Synchronizing Mulithreaded Loops Pin
pbraun25-Jul-07 12:48
pbraun25-Jul-07 12:48 
QuestionTab Controls...How can I select a Tab with a keyboard press? plz help Pin
flyingnome25-Jul-07 4:03
flyingnome25-Jul-07 4:03 
Answer[Message Deleted] Pin
flyingnome25-Jul-07 6:53
flyingnome25-Jul-07 6:53 
GeneralRe: Tab Controls...How can I select a Tab with a keyboard press? plz help Pin
Dave Kreskowiak25-Jul-07 7:22
mveDave Kreskowiak25-Jul-07 7:22 
GeneralRe: Tab Controls...How can I select a Tab with a keyboard press? plz help Pin
Paul Conrad25-Jul-07 7:40
professionalPaul Conrad25-Jul-07 7:40 
GeneralRe: Tab Controls...How can I select a Tab with a keyboard press? plz help [modified] Pin
flyingnome25-Jul-07 8:16
flyingnome25-Jul-07 8:16 
GeneralRe: Tab Controls...How can I select a Tab with a keyboard press? plz help [modified] Pin
flyingnome25-Jul-07 8:18
flyingnome25-Jul-07 8:18 
GeneralRe: Tab Controls...How can I select a Tab with a keyboard press? plz help Pin
Dave Kreskowiak25-Jul-07 13:51
mveDave Kreskowiak25-Jul-07 13:51 
GeneralRe: Tab Controls...How can I select a Tab with a keyboard press? plz help Pin
flyingnome26-Jul-07 3:33
flyingnome26-Jul-07 3:33 
GeneralRe: Tab Controls...How can I select a Tab with a keyboard press? plz help Pin
Paul Conrad25-Jul-07 7:38
professionalPaul Conrad25-Jul-07 7:38 
GeneralRe: Tab Controls...How can I select a Tab with a keyboard press? plz help Pin
flyingnome25-Jul-07 8:20
flyingnome25-Jul-07 8:20 
Questionon click enter button Pin
vikas198225-Jul-07 3:34
vikas198225-Jul-07 3:34 
AnswerRe: on click enter button Pin
ashukasama25-Jul-07 3:48
ashukasama25-Jul-07 3:48 
GeneralRe: on click enter button Pin
vikas198225-Jul-07 4:31
vikas198225-Jul-07 4:31 
GeneralRe: on click enter button Pin
ashukasama25-Jul-07 4:35
ashukasama25-Jul-07 4:35 
GeneralRe: on click enter button Pin
vikas198225-Jul-07 4:45
vikas198225-Jul-07 4:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.