SlideShare a Scribd company logo
An Introduction to POSIX Threads
Threads
POSIX Threads (pthreads)‏ IEEE's POSIX Threads Model: programming models for threads in a UNIX platform pthreads are included in the international standards ISO/IEC9945-1 pthreads programming model: creation of threads managing thread execution managing the shared resources of the process
What are Pthreads? Historically hardware vendors have implement their owm properietary versions ot threads.these implementation differed  substantially from each other making it difficult for programmers to develop portable threaded applications. In order to take full advantantage of the capabilities provided by threads,a standardised programming interface was required.
For  unix system this interface be specified by the IEEE POSIX standard. Implementation adhering to this standard are refferred to as posixthreads or pthreads. Most hardware vendors how offer pthreads in addition to the proprietory API.
Why Pthreads? The primary motivation for using Pthread is to realize potential program performance gains. When compared to cost of creating and managing process a thread can be created with much less operating system overhead.. Managing threads requires fewer system resources than managing process.
Threads Programming Model pipeline  model – threads are run one after the other master-slave  model – master (main) thread doesn't do any work, it just waits for the slave threads to finish working equal-worker  model – all threads work
Supported by the Kernel OS maintains data structures for thread state and does all of the work of thread implementation. Examples Solaris Tru64 UNIX Mac OS X Windows 2000/XP/Vista Linux version 2.6 Kernel threads
Solaris 2 Threads Solaris 2 is a version of UNIX with support for threads at the kernel and user levels,SMP,and real-time scheduling.. solaris2 implements the pthread API for thread creation and management known as UI threads. The differences between two libraries are insignificant, although most developers now opt for the Pthread library..
Solaris 2 Threads
Solaris 2 Threads
 
 
Windows 2000 Threads Windows 2000 implements the Win32 API.the Win32 API is the primary API for the family of Microsoft operating systems. A windows application runs as separate process where each process may contain one or more threads. Windows 2000 uses the one to one mapping where each user level thread maps to an associated kernel thread.
The general components of thread include: A thread ID uniquely identifying the thread. A register set representing the status of the processor. A user stack used when the thread is running is user mode. A private storage area used by various runtime libraries and dynamic link libraries.
The primary data structures of thread include: ETHREAD(executive thread block). KTHREAD(kernel thread block). TEB(thread environment block)‏
The key components of the ETHREAD include a pointer to the process to which the thread belongs and the address of the routine in which the thread starts control. the ETHREAD also contains a pointer to the corresponding KTHREAD. The KTHREAD includes scheduling and synchronization information for the thread. in addition, the KTHREAD includes the kernel stack and the pointer to the TEB.
The ETHREAD and the KTHREAD exist entirely in kernel space; this means only the kernel can access them. the TEB is a user-space structure that is accessed when the thread is running in usermode.among other fields, the TEB contains a user mode  and an array for thread-specific data.
 

More Related Content

Posix threads(asha)

  • 1. An Introduction to POSIX Threads
  • 3. POSIX Threads (pthreads)‏ IEEE's POSIX Threads Model: programming models for threads in a UNIX platform pthreads are included in the international standards ISO/IEC9945-1 pthreads programming model: creation of threads managing thread execution managing the shared resources of the process
  • 4. What are Pthreads? Historically hardware vendors have implement their owm properietary versions ot threads.these implementation differed substantially from each other making it difficult for programmers to develop portable threaded applications. In order to take full advantantage of the capabilities provided by threads,a standardised programming interface was required.
  • 5. For unix system this interface be specified by the IEEE POSIX standard. Implementation adhering to this standard are refferred to as posixthreads or pthreads. Most hardware vendors how offer pthreads in addition to the proprietory API.
  • 6. Why Pthreads? The primary motivation for using Pthread is to realize potential program performance gains. When compared to cost of creating and managing process a thread can be created with much less operating system overhead.. Managing threads requires fewer system resources than managing process.
  • 7. Threads Programming Model pipeline model – threads are run one after the other master-slave model – master (main) thread doesn't do any work, it just waits for the slave threads to finish working equal-worker model – all threads work
  • 8. Supported by the Kernel OS maintains data structures for thread state and does all of the work of thread implementation. Examples Solaris Tru64 UNIX Mac OS X Windows 2000/XP/Vista Linux version 2.6 Kernel threads
  • 9. Solaris 2 Threads Solaris 2 is a version of UNIX with support for threads at the kernel and user levels,SMP,and real-time scheduling.. solaris2 implements the pthread API for thread creation and management known as UI threads. The differences between two libraries are insignificant, although most developers now opt for the Pthread library..
  • 12.  
  • 13.  
  • 14. Windows 2000 Threads Windows 2000 implements the Win32 API.the Win32 API is the primary API for the family of Microsoft operating systems. A windows application runs as separate process where each process may contain one or more threads. Windows 2000 uses the one to one mapping where each user level thread maps to an associated kernel thread.
  • 15. The general components of thread include: A thread ID uniquely identifying the thread. A register set representing the status of the processor. A user stack used when the thread is running is user mode. A private storage area used by various runtime libraries and dynamic link libraries.
  • 16. The primary data structures of thread include: ETHREAD(executive thread block). KTHREAD(kernel thread block). TEB(thread environment block)‏
  • 17. The key components of the ETHREAD include a pointer to the process to which the thread belongs and the address of the routine in which the thread starts control. the ETHREAD also contains a pointer to the corresponding KTHREAD. The KTHREAD includes scheduling and synchronization information for the thread. in addition, the KTHREAD includes the kernel stack and the pointer to the TEB.
  • 18. The ETHREAD and the KTHREAD exist entirely in kernel space; this means only the kernel can access them. the TEB is a user-space structure that is accessed when the thread is running in usermode.among other fields, the TEB contains a user mode and an array for thread-specific data.
  • 19.