Your SlideShare is downloading. ×
Lecture 9 -_pthreads-linux_threads
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Lecture 9 -_pthreads-linux_threads

877
views

Published on

hi wassup

hi wassup

Published in: Economy & Finance

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
877
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
33
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Threads
  • 2.
  • 3. Figure 2-12. The first column lists some items shared by all threads in a process. The second one lists some items private to each thread. Thread/Process Items Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13- 6006639
  • 4. Figure 2-16. (a) A user-level threads package. (b) A threads package managed by the kernel. User Threads, Kernel Threads Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13- 6006639
  • 5. Threads in Linux
  • 6. Story of Unix (Vahalia)‏
    • Bell Labs, GE and MIT collaborating on Multics
      • Canceled in 1969
    • Multics developer Thomson, and Ritchie created an environment to support a game Space Travel , on PDP-7
    • Unix was born
  • 7. Story of Unix
    • Popular within Bell Labs: Unix programmers manual – 1971
    • Paper in SOSP: 1974, The Unix Timesharing System
    • AT&T wasn’t so interested – licensed by UC Berkeley
    • Many ports
      • Microsoft and SCO ported to Intel 8086 - XENIX
  • 8. Flavours of Unix
    • Berkeley Software Distribution: Famous for sockets
    • System V: AT&T’s version (finally got interested)‏
    • IBM – AIX
    • HP – UX
    • Sun – Solaris
      • Famous for NFS
  • 9. POSIX
    • Too many variants – needed standardization
    • 1986 - IEEE committee formed to publish a proper standard
    • POSIX: Portable Operating Systems based on unIX
    • POSIX1003.1 standard – known as POSIX.1 published in 1990
      • Minimum system call interface to be supported
  • 10. Linux
    • Tanenbaum released MINIX in 1987
      • Educational operating system
    • Linus Torvalds, inspired by MINIX, wrote Linux (developed on MINIX)‏
  • 11. Threads in Linux
    • Original: LinuxThreads (1996)‏
    • Now: Native Posix Threads Library (2005)‏
  • 12. Threads in Linux
    • Before any thread library was created:
      • Clone() system call supported by Linux
      • Creates copy of process that shares address space of the caller
  • 13. LinuxThreads
    • User-space thread library built using clone() system call
    • Basic assumption: context switches between related processes are fast enough to handle each user-level thread by one kernel thread (1:1 model)‏
  • 14. … Linux Threads
    • Since “threads” were actually separate processes, needed the concept of manager thread. This is required for (from IBM article):
      • The system must be able to react to fatal signals and kill the entire process.
      • The de-allocation of memory used as stacks must happen after a thread is finished. Therefore, the thread cannot do this itself.
      • Terminating threads must be waited on so that they don't turn into zombies.
      • The de-allocation of thread-local data requires iterating over all threads; this must be done by the manager thread.
      • If the main thread needs to call pthread_exit(), the process is not terminated. The main thread goes to sleep, and it is the job of the manager thread to wake up the main thread when all other threads have been killed.
  • 15. … Linux Threads
    • Each thread had a different process ID
    • Scheduling Handled by Kernel Scheduler
  • 16. … LinuxThreads: Limitations
    • Requires manager thread: overhead
      • Including context switching (lot of it, as everything is managed through manager thread)‏
      • Caused scalability problems
    • Each thread having different PID: POSIX incompatible
    • No concept of sending a signal to the main process (many signal-related complications)‏
    • /proc directory is flooded
    • Number of threads limited by total number of processes the architecture can support
  • 17. NPTL Goals (paper by NPTL authors)‏
    • The new threading library should be POSIX compliant.
    • The thread implementation should work well on systems with large number of processors.
    • Creating new threads for even a small piece of work should have a low startup cost.
    • The NPTL thread library should be binary compatible with LinuxThreads.
    • The new threading library should be able to take advantage of NUMA support.
  • 18. NPTL Design Decisions
    • 1:1 vs M:N threading model: 1:1 prevailed
      • No motivation to deal with complications due to the M:N threading model
      • Scheduler is fast enough O(1), can deal with large number of threads
    • No manager thread
      • All tasks taken care of by kernel itself
  • 19. … NPTL Design
    • Different threads have different thread ID, same process ID
    • Exec system call keeps same process ID, all threads of previous process are terminated.
    • /proc structure (process list) has only the first thread
    • 2 billion threads can be supported
  • 20. Pthread calls
    • int pthread_create(pthread_t * thread, const pthread_attr_t * attr, void * (*start_routine)(void *), void *arg);
      • pthread_t: thread ID
      • start_routing: function that this thread calls
      • arg; argument to this function
    • int pthread_join(pthread_t thread, void *value_ptr);
      • Waits for thread thread to finish, the functions return value is pointed to by value_ptr
  • 21. … pthread calls
    • Function to be called must be declared as a function pointer.