Showing posts with label OS-5. Show all posts
Showing posts with label OS-5. Show all posts

Monday, August 10, 2009

Substantial Information about Threads of atleast three OS
WINDOWS XP THREAD

Implements the one-to-one mapping
Each thread contains
-> A thread id
-> Register set
-> Separate user and kernel stacks
-> Private data storage area
The register set, stacks, and private storage area are known as the context of the threads
The primary data structures of a thread include:
-> ETHREAD (executive thread block)
-> KTHREAD (kernel thread block)
-> TEB (thread environment block)
JAVA THREADS

-> Java threads are managed by the JVM
-> Java threads may be created by:

Extending Thread class
Implementing the Runnable interface

Windows 2000

Implements the one-to-one mapping

Each thread contains

->A thread ID

->Register set

->Separate user and kernel stacks for user and kernel modes

->Private data storage area used by various run-time libraries and dynamic link libraries (DDLs)

->The latter three are known as the context of the thread and are architecture-specific to HW.





Wednesday, August 5, 2009

Procedure-Consumer Example

PROCEDURE

A Procedure encapsulates a task composed of Steps (and possibly, SubSteps). Procedures are usually performed sequentially, unless individual Steps direct the reader explicitly.Often it is important to assure that certain conditions exist before a procedure is performed, and that the outcome of the procedure matches the expected results. DocBook does not provide explicit semantic markup for these pre- and post-conditions. Instead, they must be described as steps (check the pre-conditions in the first step and the results in the last step), or described outside the body of the procedure.

CONSUMER

Consumer is a broad label that refers to any individuals or households that use goods and services generated within the economy. The concept of a consumer is used in different contexts, so that the usage and significance of the term may vary.
Thread Library

The threads library allows concurrent programming in Objective Caml. It provides multiple threads of control (also called lightweight processes) that execute concurrently in the same memory space. Threads communicate by in-place modification of shared data structures, or by sending and receiving data on communication channels.The threads library is implemented by time-sharing on a single processor. It will not take advantage of multi-processor machines. Using this library will therefore never make programs run faster. However, many programs are easier to write when structured as several communicating processes.
Kernel threads

=> Supported by the Kernel
=> Kernel can run them on multiple processors in parallel
User thread

=> Thread management done by user-level threads library
=> includes a set of registers and a stack, and shares the entire address space with the other threads in the enclosing process
=> is handled entirely in user code, usually by a special library that provides at least start, swap and suspend calls
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 systemto 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 memorywhile different processes do not share these resources.

Multithreading models

•There are three dominant models for thread libraries, each with its own trade-offs
–many threads on one LWP (many-to-one)
–one thread per LWP (one-to-one)
–many threads on many LWPs (many-to-many)
•Similar models can apply on scheduling kernel threads to real CPUs
Many-to-one
=> Many user-level threads mapped to single kernel thread

•In this model, the library maps all threads to a single lightweight process•Advantages:

–totally portable
–easy to do with few systems dependencies

•Disadvantages:

–cannot take advantage of parallelism

–may have to block for synchronous I/O

–there is a clever technique for avoiding it

•Mainly used in language systems, portable libraries
One-to-one

=>Many user-level threads mapped to single kernel thread

•In this model, the library maps each thread to a different lightweight process
•Advantages:
–can exploit parallelism, blocking system calls
•Disadvantages:–thread creation involves LWP creation
–each thread takes up kernel resources
–limiting the number of total threads
•Used in LinuxThreads and other systems where LWP creation is not too expensive
Many-to-many => Allows many user level threads to be mapped to many kernel threads
=> Allows the operating system to create a sufficient number of kernel threads

•In this model, the library has two kinds of threads: bound and unbound
–bound threads are mapped each to a single lightweight process
–unbound threads may be mapped to the same LWP
•Probably the best of both worlds
•Used in the Solaris implementation of Pthreads (and several other Unix implementations)
Benefits of Multi-Threaded Programming Multi-threading as a widespread programming and execution model allows multiple threads to exist within the context of a single process. These threads share the process' resources but are able to execute independently. The threaded programming model provides developers with a useful abstraction of concurrent execution. However, perhaps the most interesting application of the technology is when it is applied to a single process to enable parallel execution on a multiprocessor system.

This advantage of a multithreaded program allows it to operate faster on computer systems that have multiple CPUs, CPUs with multiple cores, or across a cluster of machines — because the threads of the program naturally lend themselves to truly concurrent execution. In such a case, the programmer needs to be careful to avoid race conditions, and other non-intuitive behaviors. In order for data to be correctly manipulated, threads will often need to rendezvous in time in order to process the data in the correct order. Threads may also require atomic operations (often implemented using semaphores) in order to prevent common data from being simultaneously modified, or read while in the process of being modified. Careless use of such primitives can lead to deadlocks.

Another advantage of multithreading, even for single-CPU systems, is the ability for an application to remain responsive to input. In a single threaded program, if the main execution thread blocks on a long running task, the entire application can appear to freeze. By moving such long running tasks to a worker thread that runs concurrently with the main execution thread, it is possible for the application to remain responsive to user input while executing tasks in the background.


Operating systems schedule threads in one of two ways:

1. Preemptive multithreading is generally considered the superior approach, as it allows the operating system to determine when a context switch should occur. The disadvantage to preemptive multithreading is that the system may make a context switch at an inappropriate time, causing priority inversion or other negative effects which may be avoided by cooperative multithreading.

2. Cooperative multithreading, on the other hand, relies on the threads themselves to relinquish control once they are at a stopping point. This can create problems if a thread is waiting for a resource to become available.

Traditional mainstream computing hardware did not have much support for multithreading as switching between threads was generally already quicker than full process context switches. Processors in embedded systems, which have higher requirements for real-time behaviors, might support multithreading by decreasing the thread-switch time, perhaps by allocating a dedicated register file for each thread instead of saving/restoring a common register file. In the late 1990s, the idea of executing instructions from multiple threads simultaneously has become known as simultaneous multithreading. This feature was introduced in Intel's Pentium 4 processor, with the name hyper threading.