Thursday, May 13, 2010

Exercise 10


1. Find definitions for the eight terms and concepts used in threaded programming.
a. Thread Synchronisation:-
Thread is a sequence of a program which runs a certain function within a program. As an application runs, it spawns off functions within the program as a thread. For example, mail program may need to contact the server to check for new mail, that function could be a thread. Some operating systems can run multiple threads at one time, allowing for fast execution of an application.

Thread synchronization requires that a running thread gain a "lock" on an object before it can access it. The thread will wait in line for another thread that is using the method/data member to be done with it. This is very important to prevent the corruption of program data if multiple threads will be accessing the same data. If two threads try to change a variable or execute the same method at the same, this can cause serious and difficult to find problems. Thread synchronization helps prevent this.
b. Locks
A lock is a mechanism for controlling access to something. In programming, locks are often used so that multiple programs or threads of a program can share a resource - for example, access to a file for updating it - on a one-at-a-time basis. Typically, a lock is of temporary duration and when the resource is no longer required, it is freed for locking and use by the next sharer in a queue.
From a system point-of-view, locking is a method of synchronizing potentially concurrent uses of a database or other common resource. An operating system may enforce locking or some other mechanism in order to ensure that actions occur in the right. An operating system must also provide for means to ensure that two programs do not become dependent on each other for the release of a lock, a situation known as a deadlock in which the programs are essentially halted.
c. Deadlock
 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 is called deadlock.It 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.
d.Semaphores
A semaphore is a hardware or software flag. In multitasking systems, a semaphore is a variable with a value that indicates the status of a common resource. Its used to lock the resource that is being used. A process needing the resource checks the semaphore to etermine the resource's status and then decides how to proceed.
In programming, especially in UNIX systems, semaphores are a technique for coordinating or synchronizing activities in which multiple process compete for the same operating system resources. A semaphore is a value in a designated place in operating system (or kernel) storage that each process can check and then change.

Depending on the value that is found, the process can use the resource or will find that it is already in use and must wait for some period before trying again.
Semaphores can be binary (0 or 1) or can have additional values.
Semaphores are one of the techniques for inter process communication .The C programming language provides a set of interfaces or "functions" for managing semaphores.
e. Mutex (Mutual Exclusion)
In computer programming, a mutex (mutual exclusion object) is a program object that is created so that multiple program thread can take turns sharing the same resource, such as access to a file. Typically, when a program is started, it creates a mutex for a given resource at the beginning by requesting it from the system and the system returns a unique name or ID for it. After that, any thread needing the resource must use the mutex to lock the resource from other threads while it is using the resource. If the mutex is already locked, a thread needing the resource is typically queued by the system and then given control when the mutex becomes unlocked (when once more, the mutex is locked during the new thread's use of the resource).
f.Thread
By definition, Thread is a piece of program which is running two or more concurrent task. Consider a sequential program which is printing a series of prime number on the screen. This program will start at line 1 and will run through the lines until the end. We have to note here that at any given time while the program is running, there is only one point of execution.
A thread is quite similar to the sequential program, where it differs, is when a stream of execution or part of the program that can run simultaneously and independently of everything else that might be happening with the rest of the program.
Without thread, a CPU intensive task can hold up the entire CPU for some time and just imagine if there in infinite loop in the same program. With thread, the part that is not part of the loop can continue processing without waiting for the infinite loop to finish.
G. Event
Lots of programs and some operating system are good examples of events. This normally occurs when a key is pressed or the mouse pointer has been rolled over some specific part of the screen which triggers a piece of program to be executed. For example, just by rolling the mouse pointer over the start icon on the Windows desktop, this will cause an event which will display a message, here is start.
8. Waitable timer
This is a very light weight object that is used to schedule an event for a specified time.


No comments:

Post a Comment