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 THREAD OF AT LEAST THREE OS
=Java Thread
Java thread are managed by the JVM
Java thread may created by:
> Extending thread class> Implementing the Runnable inteface
In Java, each thread is represented by an object of class java.lang.Thread, which handles the necessary bookkeeping and provides methods for controlling the thread.

=Windows 2000Implements the one-to-one mappingEach 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

=LINUX THREADS
- Linux refers to them as tasks rather than threads
- Thread creation is done through clone() system call
- clone() allows a child task to share the address space of the parent task (process)

Thursday, July 30, 2009

operating system 5


Thread


*Single Threaded Process & *Multi-threaded Proces








-Benefits of Multi-threaded Programming
*Responsiveness - Parts of a program can continue running even if parts of it are blocked. Book points out that a multi-threaded web browser could still allow user interaction in one thread while downloading a gif in another thread…
*Resource Sharing – pros and cons here. By sharing memory or other resources (files, etc.) the threads share the same address space. (there are issues here…)
*Economy – since threads share resources, it is easier to context-switch threads than context-switching processes. This should be clear.
*Utilization of MP Architectures – there will be significant increases in performance in a multiprocessor system, where different threads may be running simultaneously (in parallel) on multiple processors.
*Of course, there’s never ‘a free lunch,’ as we will see later. (There’s always a cost…; nothing this good comes free. J )

-User Thread


^Thread management done by user-level threads library
^Three primary thread libraries:
-POSIX Pthreads
-Win32 threads


-Kernel Thread


*Supported by the Kernel
*Examples
-Windows XP/2000
-Solaris
-Linux
-Tru64 UNIX
-Mac OS X


-Thread Library


-Programmers need help and receive development help via thread libraries germane to specific development APIs..
*A thread library provides an API for creating and managing threads. Java has an extensive API for thread creation and management.
-There are two primary ways to implement thread libraries:
1. Provide thread library entirely in user space – no kernel support
-All code and data structures for the library exist in user space.
-And, invoking a local function call to the library in user space is NOT a system call, but rather a local function call. (this is good).
2. Implement a kernel-level library supported by the OS.
-Here, code and data structures exist in kernel space.
-Unfortunately, in invoking a function call to the library, there is a system call to the kernel for support.
-Multithreading Model
+Many-to-one Model

•Each user thread maps to one kernel thread
•Is this implementation good (concurrency vs. efficiency)?
–Good concurrency, why? (blocking syscall does not affect other threads)
–Expensive, why? (user-thread creation -> kernel-thread creation)
•How to have both good concurrency and efficiency?






+One-to-one model

*Each user-level thread maps to kernel thread
*Examples
-Windows NT/XP/2000
-Linux
-Solaris 9 and later


+Many-to-many model


•Many user threads are mapped to a smaller or equal number of kernel threads. –Why is this better than Many-to-one? (concurrency & multi-processor) –Why is this better than one-to-one? (efficiency) •Like one-to-one concurrency? –Two-level model