Units 1-4 Flashcards
For each of the following system configurations, explain whether it is capable of being concurrent, parallel, both, or neither. Briefly justify each answer.
(a) One processor, two activities
(b) Four processors, two activities
(c) Three processors, five activities
(d) Two processors, one activity
(a) Concurrent, not parallel - take turns to use the processor in pseudoparallel fashion.
(b) Parallel (and therefore concurrent) - two activities can run simultaneously on two of the processors, with two processors idle.
(c) Concurrency is possible by sharing the processors among all the activities. Some parallelism is possible because there are multiple processors but not all activities can be active at once.
(d) Neither concurrent nor parallel because one activity by definition can only be doing one thing at a time.
Explain the need for a processor to run in at least two modes, including a supervisor mode.
A processor must mediate between concurrently running processes to prevent errors. The superviser mode is used for privileged instructions, including those involved in performing input/output, and controlling entry/exit from supervisor mode. Control can be exercised over how privileged instructions are executed, and user processes can be prevented from causing certain kinds of system failures or arbitrarily executing sensitive code, because the processor can only perform these instructions when it is in the right mode. This allows policies to be enforced.
Explain how the following mechanisms are related:
- entry protocols
- exit protocols
- semaphores
Shared data needs to be protected so that only one process at a time can have access to it. A semaphore is a mechanism designed to protect shared data, through ‘wait’ and ‘signal’ operations which function like an entry and an exit protocol respectively.
A process must execute the entry protocol before using shared data. If another process is already using the data, the entry protocol makes the new process wait. Once a process has finished using shared data, it executes the exit protocol, which alerts waiting processes that they can try to execute the entry protocol again.
Give a definition of the term “virtual machine”.
A virtual machine is an abstract computing device that is implemented in software. A virtual machine defines a certain set of instructions and how code and data are organised in the machine’s memory.
Name two components of the Java Virtual Machine and state what they do.
Bytecode verifier: checks whether bytecode about to be executed has not been tampered with.
Class loader: loads classes at runtime into the JVM’s memory.
Bytecode interpreter: interprets and executes the code.
Garbage collector: reclaims the memory occupied by unused objects from the heap.
JIT compiler: compiles a sequence of VM instructions into machine code as the sequence is being executed.
Briefly state three reasons why concurrent and distributed systems are important.
- Better utilisation of available hardware, software and data.
- Less chance of bottlenecks.
- Improved fault-tolerance.
- Better scalability.
Briefly state the main difference between a process and a thread and hence explain the advantages that threads have over processes.
- Process: A program being executed. Has its own set of memory space. Context switches require a substanational amount of data to be stored in order to resume.
- Thread: a lightweight process that shares data between thread instances. Share a common address space. Context switches require less data to be stored. Can be created at will to handle demand.
Briefly explain the facilities built into the core Java language to support mutual exclusion.
Mutual exclusion is provided by synchronized access to methods that modify shared data; the synchronized keyword can also be used in the method body to set up a lock before accessing shared data and this approach enables fine granularity of locks.
Briefly explain the facilities built into the core Java language to support condition synchronisation.
Conditional synchronisation is provided by Java through a wait/notify mechanism. Threads wait for a condition/lock to come true and then execute the protected code. Once finished, a notification signals the other threads that shared data/protected code can now be accessed again.
What does the term thread safe mean when applied to a Java class?
A class is thread safe if it can be executed concurrently by multiple threads without the shared data getting into an inconsistent state.
Explain two limitations of the built-in mechanism of ‘monitors’ and how they were addressed by the concurrency utilities introduced by Java 1.5.
Java’s built-in monitors are limited in the sense that they have a single implicit condition variable per lock and there is no possibility of retracting lock acquisition attempts.
The concurrency utilities introduced the Lock and Condition interfaces. The former has a tryLock method that doesn’t block if the lock is not available, and the latter allows the developer to associate multiple explicit conditions to each lock.
Explain the terms sequential and parallel systems. Under what circumstances is parallel processing possible?
Sequential system: A system in which each activity must complete execution before another activity can start.
Parallel system: A concurrent system that can really carry out a number of activities simultaneously because it has more than one processor.
Is a concurrent system always parallel? Explain your answer.
No. A concurrent system can only be parallel if it has more than one processor. A concurrent system can be psuedo-parallel if it shares processor time between a number of activities but only one activity is actually running at any given time. This appears to the user as if it were a parallel system.
In Java, what is the purpose of the Thread method yield()and when might you use it?
The yield method is invoked to indicate that the currently running thread can allow other threads a chance to proceed.
This may be necessary in cooperative multitasking systems in order to force a thread to take a break.
Briefly explain the concept of a reentrant lock.
A re-entrant lock can be reacquired by a thread that already holds it.
Summarise the main benefits and costs of mobile systems.
**Benefits: **users can communicate and access the distributed system from a wider variety of locations, and share facilities and data. For mobile systems that are wireless there are additional benefits of avoiding the cost and disruption of fixed wiring installation.
Costs: Possibly increased security risk in allowing mobile users to link to a system (wirelessly or not). Mobile components such as laptops are more easily stolen or lost than fixed components. Wireless communications are more vulnerable to interception and lower in bandwidth.
What does it mean to say a mobile system is location-aware?
Systems that are location-aware can display locally relevant information or otherwise behave in different ways depending on their physical location.
Describe the fetch-execute cycle with reference to the program counter, the CPU, memory, registers and the bus.
Program counter is used to keep track of which instruction is required next from a list of instructions in main memory. The CPU continually fetches the next instruction from memory and places it in the instruction register. It then executes the instruction to completion using registers for storage. Data may also be written to/read from cache main memory, via the bus. The program counter is then updated.