Re: Explain this about threads
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Sat, 22 Sep 2007 18:40:55 +0200
"Jon Slaughter" <Jon_Slaughter@xxxxxxxxxxx> wrote in message news:av3Ji.8375$JD.7852@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
"Instead of just waiting for its time slice to expire, a thread can block each time it initiates a time-consuming activity in another thread until the activity finishes. This is better than spinning in a polling loop waiting for completion because it allows other threads to run sooner than they would if the system had to rely solely on expiration of a time slice to turn its attention to some other thread."
I don't get the "a thread can block each time...". What does it mean by blocking? Does it mean that if thread B needs something from thread A that thread A stops thread B from running until its finished but not interfer with some other thread C?
Thanks,
Jon
Adding to what others have said in this thread:
1) You should never SpinWait on a single processor machine, doing so prevents other threads in the system to make progress( unless this is exactly what you are looking for).
Waiting for an event (whatever) from another thread in a SpinWait loop, prevents the other thread to signal the event, so basically you are wasting CPU cycles for nothing.
2) Define the count as such that you spin for less than the time needed to perform a transition to the kernel and back, when waiting for an event. Spinning for a longer period is just a waste of CPU cycles, you better give up your quantum by calling Sleep(1) or PInvoke the Kernel32 "SwitchToThread" API in that case.
Willy.
.
- Follow-Ups:
- Re: Explain this about threads
- From: Jon Slaughter
- Re: Explain this about threads
- From: Mads Bondo Dydensborg
- Re: Explain this about threads
- References:
- Explain this about threads
- From: Jon Slaughter
- Explain this about threads
- Prev by Date: Re: Where is System.Collections when using csc.exe
- Next by Date: Re: Form.ShowDialog(), how to disable exiting on button click
- Previous by thread: Re: Explain this about threads
- Next by thread: Re: Explain this about threads
- Index(es):