Thursday, November 5, 2009

Exercise 10

1. Thread Syncronisation

"In a multithreaded environment, each thread has its own local thread stack and registers. If multiple threads access the same resource for read and write, the value may not be the correct value. For example, let's say our application contains two threads, one thread for reading content from the file and another thread writing the content to the file. If the write thread tries to write and the read thread tries to read the same data, the data might become corrupted. In this situation, we want to lock the file access. The thread synchronization has two stages. Signaled and non-signaled.

The signaled state allows objects to access and modify data. The non-signaled state does allow accessing or modifying the data in the thread local stack." http://www.codeproject.com/KB/threads/Synchronization.aspx

2. Locks

A Lock is a synchronization method that controls access to resources for threads and processes. Data integrity of resources is ensured through the use of locks as it does not allow any 2 threads to access the same 1 data source at the same time.

3. Dead Locks

"In computer science, deadlock refers to a specific condition when two or more processes are each waiting for each other to release a resource, or more than two processes are waiting for resources in a circular chain (see Necessary conditions). Deadlock is a common problem in multiprocessing where many processes share a specific type of mutually exclusive resource known as a software lock or soft lock. Computers intended for the time-sharing and/or real-time markets are often equipped with a hardware lock (or hard lock) which guarantees exclusive access to processes, forcing serialized access. Deadlocks are particularly troubling because there is no general solution to avoid (soft) deadlocks." http://en.wikipedia.org/wiki/Deadlock

4. Semaphores

"Semaphores are routines that ensure orderly access to regions of code. Like spinlocks, semaphores guard kernel data structures by controlling access to regions of code associated with a set of data structures. Unlike spinlocks, semaphores require the waiting thread to relinquish the CPU while awaiting the lock. Semaphores are implemented using a swtch() to allow another thread to run....Semaphores serve two functions mutual exclusion and synchronization. Mutual-exclusion semaphores protect data and are further classified by their degree of restrictiveness." http://docs.hp.com/en/5965-4643/ch01s08.html

5. Mutex

"A mutex object is a synchronization object whose state is set to signaled when it is not owned by any thread, and nonsignaled when it is owned. Only one thread at a time can own a mutex object, whose name comes from the fact that it is useful in coordinating mutually exclusive access to a shared resource. For example, to prevent two threads from writing to shared memory at the same time, each thread waits for ownership of a mutex object before executing the code that accesses the memory. After writing to the shared memory, the thread releases the mutex object." http://msdn.microsoft.com/en-us/library/ms684266%28VS.85%29.aspx

6. Thread

"In computer science, a thread of execution results from a fork of a computer program into two or more concurrently running tasks. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process. Multiple threads can exist within the same process and share resources such as memory, while different processes do not share these resources." http://en.wikipedia.org/wiki/Thread_%28computer_science%29

7. Event

"In computer science, an event is a type of synchronization mechanism that is used to indicate to waiting processes when a particular condition has become true.

An event is an abstract data type with a boolean state and the following operations:

  • wait - when executed, causes the executing process to suspend until the event's state is set to true. If the state is already set to true has no effect.
  • set - sets the event's state to true, release all waiting processes.
  • clear - sets the event's state to false.

Different implementations of events may provide different subsets of these possible operations; for example, the implementation provided by Microsoft Windows provides the operations wait (WaitForObject and related functions), set (SetEvent), and clear (ResetEvent). An option that may be specified during creation of the event object changes the behaviour of SetEvent so that only a single process is released and the state is automatically returned to false after that process is released." http://en.wikipedia.org/wiki/Event_%28synchronization_primitive%29

8. Waitable Timer

"A waitable timer object is a synchronization object whose state is set to signaled when the specified due time arrives. There are two types of waitable timers that can be created: manual-reset and synchronization. A timer of either type can also be a periodic timer.

ObjectDescription
manual-reset timerA timer whose state remains signaled until SetWaitableTimer is called to establish a new due time.
synchronization timerA timer whose state remains signaled until a thread completes a wait operation on the timer object.
periodic timerA timer that is reactivated each time the specified period expires, until the timer is reset or canceled. A periodic timer is either a periodic manual-reset timer or a periodic synchronization timer.
" http://msdn.microsoft.com/en-us/library/ms687012%28VS.85%29.aspx

No comments:

Post a Comment