Unformatted text preview:

CSC 4320/6320 Operating Systems Lecture 4 ThreadsChapter 4: ThreadsObjectivesThreadsSingle and Multithreaded ProcessesMultithreaded Server ArchitectureBenefitsProcess VsThreadsConcurrent Execution on a Single-core SystemMulticore ProgrammingUser ThreadsThreads in User SpaceKernel ThreadsThreads in Kernel SpaceHybrid ImplementationsAdvantage-Disadvantage FactorsMultithreading ModelsMany-to-OneOne-to-OneMany-to-Many ModelTwo-level ModelThreads Vs MultiprocessesThread LibrariesPthreadsSlide 25Win32 Thread ProgramJava ThreadsThreading IssuesSemantics of fork() and exec()Thread CancellationSignal HandlingSlide 32Thread PoolsThread Specific DataScheduler ActivationsLightweight Processes (LWP)Operating System ExamplesWindows XP ThreadsSlide 39Linux ThreadsSlide 41End of Lecture 4Saurav KarmakarChapter 4: ThreadsOverviewMultithreading ModelsThread LibrariesThreading IssuesOperating System ExamplesWindows XP ThreadsLinux ThreadsObjectivesTo introduce the notion of a thread — a fundamental unit of CPU utilization that forms the basis of multithreaded computer systemsTo discuss the APIs for the Pthreads, Win32, and Java thread librariesTo examine issues related to multithreaded programmingThreadsA thread is a single sequence stream within in a process. Processes are used to group resources together and threads are the entities scheduled for execution on the CPU.Sometimes called lightweight processes. A thread has or consists of thread id, a program counter (PC), a register set, and a stack space. Threads are not independent of one other like processesSingle and Multithreaded ProcessesMultithreaded Server Architecture When some similar tasks to be served by a server should it create a process or a thread?BenefitsResponsivenessResource SharingEconomyScalabilityProcess VsThreadsSimilaritiesThreads share CPU and only one thread active (running) at a time. Threads within a processes execute sequentially. Thread can create children. If one thread is blocked, another thread can run. DifferencesThreads are not independent of one another. All threads can access every address in the task . Threads are designed to assist one other. Note that processes might or might not assist one another because processes may originate from different users.Concurrent Execution on a Single-core SystemParallel Execution on a Multicore SystemMulticore ProgrammingMulticore systems putting pressure on programmers, challenges includeDividing activitiesBalanceData splittingData dependencyTesting and debuggingUser ThreadsThread management done by user-level threads libraryThread switching does not need to call operating system and to cause interrupt to the kernel. The kernel knows nothing about user-level threads and manages them as if they were single-threaded processes. Three primary thread libraries: POSIX Pthreads Win32 threads Java threadsThreads in User SpaceEach process needs a thread tableSimilar to a process table, but tracks only:○Program Counter○Stack Pointer○Registers○StateTable managed by the run-time systemKernel ThreadsSupported by the KernelThe kernel has a thread table that keeps track of all threads in the system.Operating Systems kernel provides system call to create and manage threads. ExamplesWindows XP/2000SolarisLinuxTru64 UNIXMac OS XThreads in Kernel SpacePut the concept of the thread in the kernel There is no need of a run-time systemThe kernel has a thread tableThreads make calls to the kernel for thread creation/terminationKernel holds each thread’s registers, state, etc...Hybrid ImplementationsTrys to get to advantage of both the designsUser and kernel threads are implemented where they will be more efficientDisadvantage : Complicated design by farAdvantage-Disadvantage FactorsRepresentaionManagementSpeed and EfficiencyScheduler DecesionOverheadsApplicationMultithreading ModelsDescribes the relationship between user threads and kernel threadsThree general types :Many-to-OneOne-to-OneMany-to-ManyMany-to-OneMany user-level threads mapped to single kernel threadThread management – in user spaceEntire process gets blocked if one blocks.Only one thread can use kernel at a timeExamples:Solaris Green ThreadsGNU Portable ThreadsOne-to-OneEach user-level thread maps to a kernel threadBetter in concurrencyOnly drawback is creating one of this kind requires corresponding kernel thread creationExamplesWindows NT/XP/2000LinuxSolaris 9 and laterMany-to-Many ModelAllows many user level threads to be mapped to many (smaller or equal #) kernel threads(# depends on application/machine)Allows the operating system to create a sufficient number of kernel threadsOn a blocking call kernel can schedule another threadExample :Solaris prior to version 9Windows NT/2000 with the ThreadFiber packageTwo-level ModelSimilar to M:M, except that it allows a user thread to be bound to kernel threadExamplesIRIXHP-UXTru64 UNIXSolaris 8 and earlierThreads Vs MultiprocessesAdvantages :Context SwitchingSharingDisadvantages :BlockingSecurityThread LibrariesThread library provides programmer with API for creating and managing threadsTwo primary ways of implementingLibrary entirely in user spaceKernel-level library supported by the OSPthreadsMay be provided either as user-level or kernel-level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)Win32 Thread ProgramJava ThreadsJava threads are managed by the JVMTypically implemented using the threads model provided by underlying OSJava threads may be created by:Extending Thread classImplementing the Runnable interfaceThreading IssuesSemantics of fork() and exec() system callsThread cancellation of target threadAsynchronous or deferredSignal handlingThread poolsThread-specific dataScheduler activationsSemantics of fork() and exec()Does fork() duplicate only the calling thread or all threads?What about exec() ?What type of fork() is better ?Thread CancellationTerminating a thread before it has


View Full Document

GSU CSC 4320 - l4

Documents in this Course
l13

l13

35 pages

l6

l6

76 pages

l8

l8

57 pages

l7

l7

45 pages

l2

l2

90 pages

l12

l12

35 pages

l11

l11

54 pages

l5

l5

57 pages

Load more
Download l4
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view l4 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view l4 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?