SPECIMEN EXAM Flashcards
Q1 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
(5 marks)
(a)
One processor, two activities – concurrent but not parallel. Two activities can share one processor by taking turns to use the processor in pseudoparallel
fashion.
(b)
Four processors, two activities – parallel (and therefore concurrent) because two activities can run simultaneously on two of the processors, with two processors idle.
(c)
Three processors, five activities – 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)
Two processors, one activity – neither concurrent nor parallel because one activity by definition can only be doing one thing at a time.
[An alternative answer is that parallelism or concurrency are possible if the
activity can be broken down into two or more co-operating sub-activities.]
Q2 Explain the need for a processor to run in at least two modes, including a supervisor mode.
(5 marks)
A processor must mediate between concurrently running processes to prevent errors.
To achieve this, a processor must be able to run in at least two modes, one of which is used for privileged instructions called the supervisor mode.
Privileged instructions include those involved in performing input and output, as well as those controlling entry and 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.
Q3 Explain how the following mechanisms are related: • entry protocols • exit protocols • semaphores (5 marks)
When several concurrently executing processes share data, the 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 its operations ‘wait’ and ‘signal’ which function like an entry and an exit protocol respectively.
Protection can be achieved by requiring that a process executes the entry protocol before using the shared data. If another process is already using the shared data, then the entry protocol will make the new process wait. Once a process has finished using the shared data it should execute the exit protocol. This will then alert waiting processes that they can try to execute the entry protocol again. Or if no processes are waiting, allow the next new process that wishes to execute the entry protocol.
Q4 (a) Give a definition of the term “virtual machine”. (b) Name two components of the Java Virtual Machine and state what they do. (5 marks)
(a)
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.
(b)
The JVM includes a bytecode verifier that checks whether the bytecode about to be executed has not been tampered with. The JVM also includes a class loader, which loads classes at runtime into the JVM’s memory.
Other components are the bytecode interpreter, garbage collector and JIT
compiler.
Q5 Explain the following statement: “Java’s RMI is a form of communication that follows the distributed object paradigm”. (5 marks)
The distributed object paradigm extends the object-oriented paradigm to a distributed setting, so that local and remote objects are treated in the same way and have the same capabilities.
RMI is effectively extending the way that objects invoke methods on other objects to a distributed setting, and hence belongs to the distributed objects paradigm. RMI works by adding an additional layer that deals with the lower level details of the communication, such as data marshalling and sockets. To use RMI requires the existence of a registry so that objects can look up where other objects are located, in order to invoke methods on them.
Q6 The execution of three transactions T1 ,T2 and T3 involving three objects A, B and C is interleaved as shown below:
step T1 T2 T3
1 A.read1()
2 A.read2()
3 B.read2()
4 B.read3()
5 C.write1()
6 B.write2()
7 A.write1()
8 B.write3()
(a)
Explain what is meant by ‘conflicting operations’.
(b)
List the conflicting operations in Schedule 1, indicating the order of transaction execution (you may use the step numbers to indicate which operations conflict).
(c)
Show the precedence graph for Schedule 1 and explain whether it is serializable.
(5 marks)
(a) Operations are conflicting if the order in which they are carried out affects the result. (b) The conflicting operations: 2 and 7, T2
Q7 What are the three main categories of components in the MVC approach and what are their roles? Illustrate your answer with an example for each category.
(5 marks)
MVC defines three categories of components: model, view, and controller.
The model is the abstraction of all the domain data in the system. It is the bank account in a banking application, or a shopping cart in an e-commerce system.
The view is the visualisation of the model. In a web application, the view consists of the HTML pages and the components that create the HTML pages sent to web browsers, the WAP pages sent to mobile devices, or the user interface components sent to a dedicated client.
The controller is the set of components that manage the communications between model and view.
Q8 Explain the difference between pull technology and push technology when dealing with clients in a web application. State one approach to implementing push technology.
(5 marks)
Pull technology is the normal client-server approach where the client receives information or updates only in response to a request that it sends to the server.
With push technology, the server can notify its clients of any significant changes without the clients having to explicitly make a request each time.
This normally requires clients to register with the server in some way, or to subscribe to a service to indicate an interest in updates. The server may update each client individually or may use some more efficient approach such as multicasting where one message is sent to many clients.
Possible approaches to push technology include (only 1 name required, no details required)
• multipart/x-mixed-replace;
• UDP;
• multicast UDP;
• TCP;
• messaging services (such as JMS).
Q9 For each of the following cryptographic services give an example of a scenario in which you might want to make use of it, with a brief explanation of why the service is an appropriate one for that scenario.
• signature
• certificate
(5 marks)
- Signature
Scenario: the recipient wants to check the sender’s identity.
The sender self-authenticates.
This could be used in communications where little is at stake, or where the recipient trusts the sender to self-authenticate, because there is no third-party checking the sender’s identity. - Certificate
Scenario: the recipient wants to check the sender’s identity and requires third-party checking of the identity.
This might be used in more important communications, for example, where confidential information might be disclosed and it is important to fully authenticate the sender.
Q10 Describe the main function of the ORB in CORBA.
5 marks
The main functions of the ORB in CORBA are:
• implementing an object request broker service;
• locating objects able to meet a software request, that is, finding objects able to provide a service to another object;
• preparing an object to receive a software request;
• communicating data between two objects taking part in a software interaction.
The question can also be answered in terms of support for transparencies:
• location transparency – the location of an object is transparent to an object requesting a service;
• implementation transparency – the implementation language of an object is hidden, and the platform is not specified;
• object activation state transparency – the client is not concerned with whether or not a server is actually running or a server object has been activated;
• communication mechanism transparency – the protocol used by ORBs to communicate with each other is transparent to an object requesting a service.
(5 marks)
Q11a Consider the following Java class Account to represent a bank account, with data field balance, and two operations debit and credit which can update the balance.
public class Account { protected int balance;
public Account (int balance) { this.balance = balance; }
public void debit (int a)
{ balance = balance - a; }
public void credit (int a)
{ balance = balance + a; }
}
Consider a scenario which creates an Account object myAcc with a balance of 10 and two threads T1 and T2, whereby
T1 calls myAcc.debit(15) and
T2 calls myAcc.credit(20).
(a)
(i) Give a definition of a thread-safe class.
(ii) Show, using the example scenario, how class Account violates the definition.
(iii) What is the general problem of which the scenario is an example?
(5 marks)
(a)
(i)
A class is considered thread-safe if its instances behave under concurrent method calls as if they were called sequentially. In other words, it is not possible for a multithreaded application to observe an instance of that class in an inconsistent state, i.e. a state that could not be observed by a single-threaded application.
(ii)
For the example scenario, a sequential execution of
myAcc.credit(20);
myAcc.debit(15);
will lead to a balance of 15, but with two concurrent threads it could lead to a balance of 30. Consider that T2 is interrupted after computing the sum balance + 20. At that point T1 executes the call to debit, leaving a balance of −5. Now T2 resumes execution and assigns 30 to balance.
(iii)
This is an example of the lost update problem.
(5 marks)
Q11b public class Account { protected int balance;
public Account (int balance) { this.balance = balance; }
public void debit (int a)
{ balance = balance - a; }
public void credit (int a)
{ balance = balance + a; }
}
Write a class BlockingAccount which is a thread safe version of Account, and in which, additionally, the debit operation blocks until balance is greater than or equal to the amount to be debited. Note: You must use Java’s built-in mechanisms, NOT the Java 1.5 concurrency utilities. (5 marks)
public class BlockingAccount { protected int balance;
public BlockingAccount (int balance) { this.balance = balance; }
public synchronized void debit (int a)
{
while (balance
Q11c Explain two limitations of the built-in mechanisms used in the previous question (BlockingAccount used …) and how they were addressed by the concurrency utilities introduced by Java 1.5. (5 marks)
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.
Lock has a tryLock method that doesn’t block if the lock is not available.
Condition allows the developer to associate multiple explicit conditions to each lock.
Note: The exact names of interfaces and methods do not have to be fully correct as long as the explanation is clear.
Q11d Explain and compare the thread safety levels of classes Account (ie no sync) and BlockingAccount (ie with sync’d methods).
Discuss why there is a need to identify various thread safety levels and what their existence implies for developers.
(5 marks)
Account is thread-compatible because it does not use internal synchronisation and hence requires every method call to be externally synchronised.
BlockingAccount is thread-safe because no external synchronisation is necessary for calling its methods.
Identification of the various thread safety levels is necessary because there are different ways for making classes behave correctly in a concurrent setting (e.g. by making the data immutable or by various degrees of internal and external synchronisation). This means that class developers have to document precisely the class’s safety level and which (sequences of) methods, if any, require external synchronisation.
Q11e Describe a schedule for the example scenario, but using BlockingAccount instead of Account, indicating for each thread the states it goes through in the Java Thread state model.
Note: Assume the two threads are NOT in the NEW state. For full marks provide a schedule that uses three different states.
(5 marks)
We assume both threads are in the RUNNABLE state.
One of them is scheduled for execution, let’s assume it is T1. It acquires the lock on the account, and starts evaluating the while condition.
At this moment, T2 is scheduled for execution, it tries to obtain the lock, but since it is held by T1, T2 becomes BLOCKED.
Now T1 resumes execution, enters the while loop (because it is attempting to debit 15 from an account holding only 10) and calls wait. This releases the lock and T1 gets into the WAITING state.
T2 is now able to get the lock, becomes RUNNABLE and executes the credit operation, which notifies T1.
T1 thus returns to the RUNNABLE state and completes the debit operation.