Prev | Current Page 481 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

Threads wait for an event by calling the inherited
WaitHandle.WaitOne method, which is the same method you call to wait on a Mutex to become
signaled.
We were careful in stating that a waiting thread is released when the event becomes signaled.
It??™s possible that multiple threads could be released when an event becomes signaled.
That, in fact, is the difference between ManualResetEvent and AutoResetEvent. When a
ManualResetEvent becomes signaled, all threads waiting on it are released. It stays signaled
until someone calls its Reset method. If any thread calls WaitOne() while the ManualResetEvent
is already signaled, then the wait is immediately completed successfully. On the other hand,
AutoResetEvent objects only release one waiting thread and then immediately reset to the
unsignaled set automatically. You can imagine that all threads waiting on the AutoResetEvent
are waiting in a queue, where only the first thread in the queue is released when the event
becomes signaled. However, even though it??™s useful to assume that the waiting threads are in
a queue, you cannot make any assumptions about which waiting thread will be released first.
AutoResetEvents are also known as sync events based on this behavior.
Using the AutoResetEvent type, you could implement a crude thread pool where several
threads wait on an AutoResetEvent signal to be told that some piece of work is available.


Pages:
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
ciekawe opony goodyear karta kredytowa millenium House Extension London zakłady bukmacherskie