Академический Документы
Профессиональный Документы
Культура Документы
user
>The parent is exiting and the 3.
Amdahl's Law (Speed up Good algorithmic description of
programs or tasks
operating systems does not allow a
of multicore systems)
solving the problem
<>Textbook uses the terms job and child to continue if its parent
Two process solution
process almost interchangeably
terminates
Assume that the load and store
<>Process a program in execution; <>Some operating systems do not
machine-language
process execution must progress in allow child to exists if its parent has 4.
instructions are atomic; that is, cannot
User to kernel thread
sequential fashion
terminated. If a process terminates, User threads - management done by be interrupted
<>Multiple parts
then all its children must also be user-level threads library
The two processes share two
>The program code, also called text terminated.
variables:
Three primary thread libraries:
section
>cascading termination. All children, POSIX Pthreads
int turn;
>Current activity including program grandchildren, etc. are terminated.
Boolean flag[2]
Windows threads
counter, processor registers
>The termination is initiated by the Java threads
The variable turn indicates whose
>Stack containing temporary data
operating system.
Kernel threads - Supported by the turn it is to enter the critical section
>Function parameters, return <>The parent process may wait for Kernel
The flag array is used to indicate if a
addresses, local variables
termination of a child process by using Examples virtually all general process is ready to enter the critical
>Data section containing global the wait()system call. The call returns purpose operating systems,
section. flag[i] = true implies that
variables
status information and the pid of the including: Windows, Solaris, Linux, process Pi is ready!
>Heap
containing
memory terminated process
3.
Synchronization Hardware
Tru64 UNIX, Mac OS X
dynamically allocated during run time
pid = wait(&status);
Many systems provide hardware
5.
Thread Library: pthread
<>Program is passive entity stored on >>If no parent waiting (did not invoke Thread library provides programmer support for implementing the critical
disk (executable file), process is active wait()) process is a zombie
section code.
with
>Program becomes process when >>If
parent
terminated
without API for creating and managing threads All solutions below based on idea of
executable file
invoking wait , process is an orphan
locking
Two primary ways of implementing
loaded into memory
and so on as detailed next
Protecting critical regions via locks
Library entirely in user space
<>Execution of program started via 4.
Inter
Process
Kernel-level library supported by Uniprocessors could disable
GUI mouse clicks, command line entry
Communication/IPC
interrupts
the OS
of its name, etc
(komunikasi intra proses)
Currently running code would
==pthread==
<>One program can be several Processes within a system may be May be provided either as user-level execute without preemption
processes
independent or cooperating
Generally too inefficient on
or kernel-level
>Consider multiple users executing Cooperating process can affect or be A POSIX standard (IEEE 1003.1c) API multiprocessor systems
the same program
affected by other processes, including for thread
Operating systems using this not
2.
Pengenalan
tentang sharing data
broadly scalable
creation and synchronization
"Process Scheduling"
Reasons for cooperating processes:
Modern machines provide special
Specification, not implementation
<>Maximize CPU use, quickly switch Information sharing
API specifies behavior of the thread atomic hardware instructions
processes onto CPU for time sharing
Computation speedup
Atomic = non-interruptible
library,
<>Process scheduler selects among Modularity
Either test memory word and set
implementation is up to development
available processes for next execution Convenience
value
of the library
on CPU
Cooperating
processes
need Common in UNIX operating systems
Or swap contents of two memory
<>Maintains scheduling queues of interprocess communication(IPC), two (Solaris, Linux, Mac OS X)
words
processes
models of IPC
4.
Mutex Locks
6.
Thread cancelation
>Job queue set of all processes in Shared memory
Terminating a thread before it has Previous solutions are complicated
the system
Message passing
and
generally
inaccessible
to
finished
>Ready queue set of all processes 5.
IPC: Shared Memory & Thread to be canceled is target applicationprogrammers
residing in main memory, ready and
Message Passing
OS designers build software tools to
thread
waiting to execute
===Shared Memory===
solve critical section problem
Two general approaches:
>Device queues set of processes An area of memory shared among
Asynchronous
cancellation Simplest is mutex lock
waiting for an I/O device
the
processes
that
wish
to terminates
the
target
thread Protect a critical section by first
>Processes migrate among the various communicate
acquire() a lock then release() the lock
immediately
queues
The communication is under the Deferred cancellation allows the Boolean variable indicating if lock is
3.
Operasi
terhadap control of the users processes not the target thread to periodically check if it available or not
"Process"
operating system.
Calls to acquire() and release() must
should be cancelled
System must provide mechanisms for:
Major
issues
is
to
provide 7.
be atomic
Thread Scheduler
process creation,
mechanism that will allow the user Both M:M and Two-level models
Usually implemented via hardware
<>Parent process create children processes to synchronize their actions require communication to maintain the atomic instructions
processes,which, in turn create other when they access shared memory.
appropriate number of kernel threads But this solution requires busy
processes, forming a tree of processes ===Message Passing===
waiting
allocated to the application
<>Generally, process identified and Mechanism for
processes to Typically use an intermediate data This lock therefore called a spinlock
managed via a process identifier (pid)
communicate and to
5.
Semaphores
structure
<>Resource sharing options
synchronize their actions
between user and kernel threads Synchronization tool that provides
>Parent and children share all Message system processes lightweight
more sophisticated ways (than Mutex
resources
communicate with each
locks)
process (LWP)
>Children share subset of parents other without resorting to shared
Appears to be a virtual processor for process to synchronize their
resources
variables
activities.
on which
>Parent and child share no resources
IPC facility provides two operations: process can schedule user thread to Semaphore S integer variable
<>Execution options
send(message)
Can only be accessed via two
run
>Parent
and
children
execute receive(message)
Each LWP attached to kernel thread indivisible (atomic) operations
concurrently
The message size is either fixed or How many LWPs to create?
6.
Classic
Problems
of
>Parent waits until children terminate variable
Synchronization
Scheduler activations provide upcalls
<>Address space
6.
Komunikasi dalam Client- - a
Bounded-Buffer Problem
>Child duplicate of parent
Server Systems:
communication mechanism from the n buffers, each can hold one item
>Child has a program loaded into it
Sockets
Semaphore mutex initialized to the
kernel to the
<>UNIX examples
Remote Procedure Calls
value 1
upcall handler in the thread library
>fork() system call creates new Pipes
Semaphore full initialized to the
This communication allows an
process
Remote Method Invocation (Java
value 0
application to
>exec() system call used after a fork() Thread
maintain the correct number kernel Semaphore empty initialized to the
to replace the process memory space 1.
Thread vs Process
value n
threads
with a new program
2.
Benefit of threads
Readers and Writers Problem
Process Synchronization
process termination,
Responsiveness may allow 1.
Readers only read the data set;
Critical-Section problem
<>Process executes last statement continued execution if part of process is Consider system of n processes {p0, they do not perform any updates
and then asks the operating system to blocked, especially important for user p1, pn-1}
Writers can both read and write
delete it using the exit() system call.
interfaces
Each process has critical section Dining-Philosophers Problem
7.
Monitors
segment ofcode