- Thread Synchronization
- Locks
- Deadlock
- Semaphores
- Mutex (mutual exclusion)
- Thread
- Event
- Waitable timer.
- When a timer is set, it is canceled if it was already active, the state of the timer is nonsignaled, and the timer is placed in the kernel timer queue.
- When a timer expires, the timer is set to the signaled state. If the timer has a completion routine, it is queued to the thread that set the timer. The completion routine remains in the asynchronous procedure call (APC) queue of the thread until the thread enters an alertable wait state. At that time, the APC is dispatched and the completion routine is called. If the timer is periodic, it is placed back in the kernel timer queue.
- When a timer is canceled, it is removed from the kernel timer queue if it was pending. If the timer had expired and there is still an APC queued to the thread that set the timer, the APC is removed from the thread's APC queue. The signaled state of the timer is not affected.
(msdn)Synchronization provides a compromise between the unstructured nature of multi threaded programming and the structured order of synchronous processing. You use synchronization techniques: To explicitly control the order in which code runs whenever tasks must be performed in a specific sequence -or- To prevent the problems that can occur when two threads share the same resource at the same time. For example, you could use synchronization to cause a display procedure to wait until a data retrieval procedure that is running on another thread is complete.
Locks are pieces of software that make sure that two processes do not get into each other's way when accessing a common resource and sequence the processes when there are dependencies among them.(Eustace, p8)
A deadlock is a case where two pieces of code are trying to access the same objects but are blocking each other from getting at the resources. (Johnson, p396)
In the .Net framework The Semaphore class is used to throttle usage of some resource. Specifically, a Semaphore creates a kernel object that supports a certain number of valid slots at once. When the slots are filled, the remaining code will block until a slot is made available by another thread releasing the slot.(Johnson, p405)
A Mutex allows synchronization (like a lock) across AppDomain and process boundaries. (Johnson, p402-405) Using a named Mutex is a common way to synchronize data across process boundaries.
A process is a running program – code, data (variables, data structures, etc) with at least one thread of execution. A thread is a flow of control through the process, plus a private stack for local data. Threads enable concurrency (Eustace, p2)
An Event provides a way to notify to multiple threads (across AppDomain and process boundaries) that some event has occurred. Events are a type of kernel object that has two states, on and off. These states allow threads across an application to wait until an event is signaled to do something specific.(Johnson, p402-406)
A waitable timer (MSDN) object is a synchronization object whose state is set to signaled when the specified due time arrives. The behavior of a waitable timer can be summarized as follows:
References
Eustace K. Concurrency and Transactions, ITC382/ITC594/ITC565 Topic 8
MSDN. Waitable Timer Objects. Retrieved on 6 July 2009, from http://msdn.microsoft.com/en-us/library/ms687012(VS.85).aspx
MSDN. Thread Synchronization. Retrieved on 6 July 2009, from http://msdn.microsoft.com/en-us/library/dsw9f9ts(VS.71).aspx
Johnson, B., Lanham, B., & Wildermuth, S. (2007). Mcpd self-paced training kit (exam 70-549): designing and developing enterprise applications using the microsoft®. net framework.
No comments:
Post a Comment