BENEFITS OF MULTITHREADED PROGRAMMING
BENEFITS
Responsiveness
Resource Sharing
Economy
Utilization of MP Architectures
[ ] Communication via mailboxes (or ports)
[ ] Processes communicate by putting and taking messages in/from mailboxes
– send(A, m) and receive(A,m)
[ ] Properties of communication link
– A link is established between two processes, if they share a mailbox
– Link maybe associated with more than two processes
– A number of different links may exist between any pair of processes; each one a separate mailbox
SYNCHRONIZATION
- - - is timekeeping which requires the coordination of events to operate a system in unison. The familiar conductor of an orchestra serves to keep the orchestra in time. Systems operating with all their parts in synchrony are said to be synchronous or in sync. Some systems may be only approximately synchronized, or plesiochronous. For some applications relative offsets between events need to be determined, for others only the order of the event is important. - - -
[ ] BLOCKING SEND – sender blocked until message is received by receiver (or by mailbox)
[ ] NON - BLOCKING SEND – sending process resumes operation right after sending
[ ] BLOCKING RECEIVE – receiver blocks until message is available
[ ] NON - BLOCKING RECEIVE – receiver retrieves a valid message or returns an error code
BUFFERING
[ ] Zero capacity – queue has length 0, no messages can be outstanding on link, sender blocks for
message exchange
[ ] Bounded capacity – queue has length N, N messages can be in queue at any point in time, sender blocks if queue is full, otherwise it may continue to execute
[ ] Unbounded capacity – queue has infinite length, sender never blocks
PRODUCER COUNTER EXAMPLE
[ ] PRODUCER – generates an integer between 0 and 9 (inclusive), then stores it in a CubbyHole object. To make the synchronization problem more interesting, the Producer sleeps for a random amount of time between 0 and 100 milliseconds before repeating the number generating cycle.
[ ] CONSUMER – consumes all integers from the CubbyHole (the exact same object into which the Producer put the integers in the first place) as quickly as they become available.
* receive(message)
* exchange messages via send/receive
* logical (e.g., logical properties) now
* Computation speed-up
* Modularity
* Convenience
[ ] Parent process creates children processes, which, in turn create other processes, forming a tree of processes.
* Resource sharing
[ ] Parent and children share all resources.
[ ] Children share subset of parent’s resources.
[ ] Parent and child share no resources.
* Execution
* Parent and children execute concurrently.
* Parent waits until children terminate.
[ ] Address space
* Child duplicate of parent.
* Child has a program loaded into it.
[ ] UNIX examples
* fork system call creates new process
* fork returns 0 to child , process id of child for parent
* exec system call used after a fork to replace the process’ memory space with a new program.
Process Termination
[ ] Process executes last statement and asks the operating system to delete it (exit).
* Output data from child to parent (via wait).
* Process’ resources are deallocated by operating system.
[ ] Parent may terminate execution of children processes (abort).
* Child has exceeded allocated resources.
* Task assigned to child is no longer required.
* Parent is exiting.
= Operating system does not allow child to continue if its parent terminates.
= Cascading termination.
* In Unix, if parent exits children are assigned init as parent
Scheduling Queue
[ ] The operating System must allocate resources to processes, enable processes to share and exchange information, protect the resources of each process from other processes and enable synchronization amongst process.
[ ] Job queue – set of all processes in the system.
[ ] Ready queue – set of all processes residing in main memory, ready and waiting to execute.
[ ] Device queues – set of processes waiting for an I/O device.
[ ] Processes migrate between the various queues.
Schedulers
[ ] Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue.
[ ] Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU.
[ ] Short-term scheduler is invoked very frequently (milliseconds) fi (must be fast).
[ ] Long-term scheduler is invoked very infrequently (seconds, minutes) fi (may be slow).
[ ] The long-term scheduler controls the degree of multiprogramming.
[ ] Processes can be described as either:
* I/O-bound process – spends more time doing I/O than computations, many short CPU bursts.
* CPU-bound process – spends more time doing computations; few very long CPU bursts.
Context Switch
[ ] When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process.
[ ] Context-switch time is overhead; the system does no useful work while switching.
[ ] Time dependent on hardware support.
[ ] An operating system executes a variety of programs
* Batch system – jobs
* Time-shared systems – user programs or tasks
[ ] Textbook uses the terms job and process almost interchangeably.
[ ] Process – a program in execution; process execution must progress in sequential fashion.
[ ] A process includes:
* program counter
* stack
* data section
Process State
[ ] As a process executes, it changes state
* new: The process is being created.
* running: Instructions are being executed.
* waiting: The process is waiting for some event to occur.
* ready: The process is waiting to be assigned to a processor
* terminated: The process has finished execution.
Diagram of Process State
Process Control Block (PCB)
Information associated with each process.
[ ] Process ID
[ ] Process state
[ ] Program counter
[ ] CPU registers
[ ] CPU scheduling information
[ ] Memory-management information
[ ] Accounting information
[ ] I/O status information
Process Control Block (PCB) :
Threads
[ ] Results from a fork of a computer program into two or more concurrently running tasks.
[ ] The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process.
[ ] Multiple threads can exist within the same process and share resources such as memory, while different processes do not share these resources.
A process that creates a particular and uniquely specified operating system; it combines user-specified options and parameters with manufacturer-supplied general-purpose or nonspecialized program subsections to produce an operating system (or other complex software) of the desired form and capacity. Abbreviated sysgen.
Operating system must be made available to hardware so hardware can start it
- Small piece of code – bootstrap loader, locates the kernel, loads it into memory, and starts it
- Sometimes two-step process where boot block at fixed location loads bootstrap loader
- When power initialized on system, execution starts at a fixed memory location
- Firmware used to hold initial boot code
- Virtual Machine
- Is a software implementation of a machine (computer) that executes programs like a real machine.
- Provides a complete system platform which supports the execution of a complete operating system (OS).
- Takes the layered approach to its logical conclusion. It treats hardware and the operating system kernel as though they were all hardware.
IMPLEMENTATION
- Modes: - virtual user mode and virtual monitor mode,
- Actual user mode and actual monitor mode
-Time - Whereas the real I/O might have taken 100 milliseconds, the virtual I/O might take less time (because it is spooled) or more time (because it is interpreted.)
- The CPU is being multi-programmed among many virtual machines, further slowing down the virtual machines in unpredictable ways.
BENEFITS
- concept provides complete protection of system resources since each virtual machine is isolated from all other virtual machines.
- perfect vehicle for operating-systems research and development. System development is done on the virtual machine, instead of on a physical machine and so does not disrupt normal system operation.
- multiple OS environments can co-exist on the same computer, in strong isolation from each other
- the virtual machine can provide an instruction set architecture (ISA) that is somewhat different from that of the real machine
- application provisioning, maintenance, high availability and disaster recovery
EXAMPLE
- A program written in Java receives services from the Java Runtime Environment (JRE) software by issuing commands to, and receiving the expected results from, the Java software. By providing these services to the program, the Java software is acting as a "virtual machine", taking the place of the operating system or hardware for which the program would ordinarily be tailored.
Simple Structure
– any part of the system may use the functionality of the rest of
the system
– MS-DOS (user programs can call low level I/O routines)
Layered Approach
– layer n can only see the functionality that layer n-1 exports
– provides good abstraction from the lower level details
• new hardware can be added if it provides the interface required of a particular layer
– system call interface is an example of layering
– can be slow if there are too many layers
Provide the interface between application programs and the kernel
Are like procedure calls
– take parameters
– calling routine waits for response
Permit application programs to access protected resources
Process Control
– create/terminate a process (including self)
File Management
– open, create
– read, write
– close, delete
– get or set file attributes
Also referred to as simply a file system or filesystem. The system that an operating system or program uses to organize and keep track of files. For example, a hierarchical file system is one that uses directories to organize files into a tree structure.
Although the operating system provides its own file management system, you can buy separate file management systems. These systems interact smoothly with the operating system but provide more features, such as improved backup procedures and stricter file protection.
Device Management
Device Management is a set of technologies, protocols and standards used to allow the remote management of mobile devices, often involving updates of firmware over the air (FOTA). The network operator, handset OEM or in some cases even the end-user (usually via a web portal) can use Device Management, also known as Mobile Device Management, or MDM, to update the handset firmware/OS, install applications and fix bugs, all over the air. Thus, large numbers of devices can be managed with single commands and the end-user is freed from the requirement to take the phone to a shop or service center to refresh or update.
Information Maintenance
– get time
– set system data (OS parameters)
– get process information (id, time used)
- Program execution – system capability to load a program into memory and to run it.
- I/O operations - since user programs cannot execute I/O operations directly, the operating system must provide some means to perform I/O.
- File-system manipulation – program capability to read, write, create, and delete files.
- Communications – exchange of information between processes executing either on the same computer or on different systems tied together by a network. Implemented via shared memory or message passing.
- Error detection – ensure correct computing by detecting errors in the CPU and memory hardware, in I/O devices, or in user programs.
OPERATING SYSTEM STRUCTURE
Operating Systems Process management
File Management
> File creation and deletion.
> Directory creation and deletion.
> Support of primitives for manipulating files and directories.
> Mapping files onto secondary storage.
> File backup on stable (nonvolatile) storage media.
> A buffer-caching system
> A general device-driver interface
> Drivers for specific hardware devices
> Storage allocation
> Disk scheduling
- The protection mechanism must:
> distinguish between authorized and unauthorized usage.
> specify the controls to be imposed.
> provide a means of enforcement.
Command Interpreter System
- Many commands are given to the operating system by control statements which deal with:
>process creation and management
>I/O handling
>secondary-storage management
>main-memory management
>file-system access
>protection
>networking