Your SlideShare is downloading. ×
0
Section04 threads
Section04 threads
Section04 threads
Section04 threads
Section04 threads
Section04 threads
Section04 threads
Section04 threads
Section04 threads
Section04 threads
Section04 threads
Section04 threads
Section04 threads
Section04 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

Section04 threads

433

Published on

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
433
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
27
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. OPERATING SYSTEMS Threads Jerry Breecher 4: Threads 1
  • 2. OPERATING SYSTEM Threads What Is In This Chapter?OverviewMultithreading ModelsThreading IssuesPthreadsWindows XP ThreadsLinux ThreadsJava Threads 4: Threads 2
  • 3. Single andTHREADS Multithreaded Processes 4: Threads 3
  • 4. BenefitsTHREADSResponsivenessResource SharingEconomyUtilization of MP Architectures 4: Threads 4
  • 5. THREADS User ThreadsThread management done by user-level threads libraryExamples- POSIX Pthreads- Mach C-threads- Solaris threads Supported by the Kernel Kernel Threads Examples - Windows 95/98/NT/2000 - Solaris - Tru64 UNIX - BeOS - Linux 4: Threads 5
  • 6. MultithreadingTHREADS ModelsMany-to-One How do user and kernelOne-to-One threads map into each other?Many-to-Many 4: Threads 6
  • 7. THREADS Many-to-OneMany user-level threadsmapped to single kernelthread.Used on systems thatdo not support kernelthreads.Examples: Solaris Green Threads GNU Portable Threads 4: Threads 7
  • 8. THREADS One-to-OneEach user-level thread maps to kernel thread.Examples- Windows 95/98/NT/2000- Linux 4: Threads 8
  • 9. Threading Issues THREADSSemantics of fork() and exec() system calls Does fork() duplicate only the calling thread or all threads?Thread cancellation Terminating a thread before it has finished Two general approaches: Asynchronous cancellation terminates the target thread immediately Deferred cancellation allows the target thread to periodically check if it should be cancelled 4: Threads 9
  • 10. Threading Issues THREADSSignal handling Signals are used in UNIX systems to notify a process that a particular event has occurred A signal handler is used to process signals 1. Signal is generated by particular event 2. Signal is delivered to a process 3. Signal is handled Options: Deliver the signal to the thread to which the signal applies Deliver the signal to every thread in the process Deliver the signal to certain threads in the process Assign a specific threa to receive all signals for the processThread pools Create a number of threads in a pool where they await work Advantages: Usually slightly faster to service a request with an existing thread than create a new thread Allows the number of threads in the application(s) to be bound to the size of the pool 4: Threads 10
  • 11. Threading Issues THREADSThread specific data Allows each thread to have its own copy of data Useful when you do not have control over the thread creation process (i.e., when using a thread pool)Scheduler activations Many:Many models require communication to maintain the appropriate number of kernel threads allocated to the application Scheduler activations provide upcalls - a communication mechanism from the kernel to the thread library This communication allows an application to maintain the correct number kernel threads 4: Threads 11
  • 12. THREADS Various ImplementationsPThreads A POSIX standard (IEEE 1003.1c) API for thread creation and synchronization API specifies behavior of the thread library, implementation is up to development of the library Common in UNIX operating systems (Solaris, Linux, Mac OS X)Windows Threads Implements the one-to-one mapping Each thread contains A thread id Register set Separate user and kernel stacks Private data storage area The register set, stacks, and private storage area are known as the context of the threads 4: Threads 12
  • 13. THREADS Various ImplementationsLinux 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)Java Threads Java threads may be created by: Extending Thread class Implementing the Runnable interface Java threads are managed by the JVM. 4: Threads 13
  • 14. Threads WRAPUPWe’ve looked in detail at how threads work. Specifically we’ve lookedat:Multithreading ModelsThreading IssuesPthreadsWindows XP ThreadsLinux ThreadsJava Threads 4: Threads 14

×