Thursday, July 30, 2009

multithreading models

  • many to one models
„ Many user-level threads mapped to single kernel thread
„ Examples:
1.Solaris Green Threads
2.GNU Portable Threads
  • one to one models

„ Each user-level thread maps to kernel thread

„ Examples

1. Windows NT/XP/2000

2.Linux

3. Solaris 9 and later

  • 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

Solaris prior to version 9

Windows NT/2000 with the ThreadFiber package

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 thread

We have taken the execution aspect of a process and separated it out into threads
◆ To make concurrency cheaper
As such, the OS now manages threads and processes
◆ All thread operations are implemented in the kernel
◆ The OS schedules all of the threads in the system
OS-managed threads are called kernel-level threadsor lightweight processes
◆ NT: threads
◆ Solaris: lightweight processes (LWP

kernel thread

We have taken the execution aspect of a process and separated it out into threads
◆ To make concurrency cheaperz
As such, the OS now manages threads and processes
◆ All thread operations are implemented in the kernel
◆ The OS schedules all of the threads in the system
OS-managed threads are called kernel-level threadsor lightweight processes
◆ NT: threads
◆ Solaris: lightweight processes (LWP

user thread

To make threads cheap and fast, they need to be implemented at user level
◆ Kernel-level threads are managed by the OS
◆ User-level threads are managed entirely by the run-time system (user-level library)z
User-level threads are small and fast
◆ A thread is simply represented by a PC, registers, stack, and small thread control block (TCB)◆ Creating a new thread, switching between threads, and synchronizing threads are done via procedure call
» No kernel involvement
◆ User-level thread operations 100x faster than kernel threads

benefits of multi threaded programming

Historically, code written is sequential, which means, code is executed one instruction after the next in a monolithic fashion, with no regard to the many possible resources available to the program. Overall performance can be serverely degraded if the program performs a blocking call. Why is it that many programs are sequential? One guess is that most of us think in a sequential manner. Parallelizing our thoughts does not come naturally nor is it an easy task.
However, with the increasing availability of Symmetric-Multiprocessing machines, and even more advanced multi-core processors; programming multithreaded code is a skill worth learning.
Threads can add substantial performance improvements to certain types of applications, even on single processor systems. Applications that require accessing data from multiple sources, performing different types of manipulation on data and/or transfering data to multiple end-points are all potential for threaded applications.
Basically, anytime a program sequence may be stopped waiting; that sequence is a good candidate for creating a thread. A program sequence may be stopped waiting for data from a hardware device, waiting for user input or waiting for a specific state or condition to be met.
NexusWare Core has enabled developers to develop and successfully deploy applications such as Lawful interception applications, Class 5 Soft-switch applications, SS7 line monitoring, SS7 STP, Suite of GSM mobile applications - SS7 Link replacement, Roaming Broker, Protocol converters, Radar data processing, defense applications and many more.
These types of applications are complex and require access and manipulation of data from many different data sources. Creating multiple threads within these applications has shown dramatic performance gains. Multi-threading are a good fit for the types of applications that are performed on NexusWare target hardware.

thread

  • single-Threaded Processes -

Single-threaded apartments consist of exactly one thread, so all COM objects that live in a single-threaded apartment can receive method calls only from the one thread that belongs to that apartment. All method calls to a COM object in a single-threaded apartment are synchronized with the windows message queue for the single-threaded apartment's thread. A process with a single thread of execution is simply a special case of this model.

  • Multi-Threaded Processes -

„ Each thread has a private stack

„ But threads share the process address space!

„ There’s no memory protection!

„ Threads could potentially write into each other’s stack