Posix threads(asha)


Published on

Published in: Education
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Posix threads(asha)

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