tailieunhanh - accelerated c# 2010 trey nash phần 8

Tham khảo tài liệu 'accelerated c# 2010 trey nash phần 8', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | CHAPTER 12 THREADING IN C When a thread has entered a locked region successfully it can give up the lock and enter a waiting queue by calling one of the overloads where the first parameter to is the object reference whose sync block represents the lock being used and the second parameter is a timeout value. returns a Boolean that indicates whether the wait succeeded or if the timeout was reached. If the wait succeeded the result is true otherwise it is false. When a thread that calls completes the wait successfully it leaves the wait state as the owner of the lock again. Note You may want to consult the MSDN documentation for the Monitor class to become familiar with the various overloads available for . If threads can give up the lock and enter into a wait state there must be some mechanism to tell the Monitor that it can give the lock back to one of the waiting threads as soon as possible. That mechanism is the method. Only the thread that currently holds the lock is allowed to call . When it s called the thread first in line in the waiting queue is moved to a ready queue. Once the thread that owns the lock releases the lock either by calling or by calling the first thread in the ready queue is allowed to run. The threads in the ready queue include those that are pulsed and those that have been blocked after a call to . Additionally the thread that owns the lock can move all waiting threads into the ready queue by calling . There are many fancy synchronization tasks that you can accomplish using the and methods. For example consider the following example that implements a handshaking mechanism between two threads. The goal is to have both threads increment a counter in an alternating manner using System using public class EntryPoint . static private int counter 0 static .