Binus Alam Sutera

Binus Alam Sutera

Tuesday, February 3, 2015

Chapter 13 Answers

Nama: Christian Gunawan
NIM: 1801384174

Kali ini saya akan menjawab Assignment #13 dari Chapter 13 Programming Language Concepts R Sebesta :


Review Questions #6-10 :

6. Describe the logical architecture of a vector processor.

Vector processor have groups of registers that store the operands of a vector operation in which the same instruction is executed on the whole group of operands simultaneously. Originally, the kinds of programs that could most benefit from this architecture were in scientific computation, an area of computing that is often the target of multiprocessor machines.


7. What is the difference between physical and logical concurrency?

Physical concurrency – Multiple independent processors (multiple threads of control)
Logical concurrency – The appearance of physical concurrency is presented by time-sharing one processor (software can be designed as if there were multiple threads of control)


8. What is a thread of control in a program?

A thread of control in a program is the sequence of program points reached as control flows through the program.


9. Why are coroutines called quasi-concurrent?
Because they have a single thread of control.


10. What is a multithreaded program?
A program designed to have more than one thread of control.


Problem Set #6-10 :

6. Suppose two tasks, A and B, must use the shared variable Buf_Size. Task A adds 2 to Buf_Size, and task B subtracts 1 from it. Assume that such arithmetic operations are done by the three-step process of fetching the current value, performing the arithmetic, and putting the new value back. In the absence of competition synchronization, what sequences of events are possible and what values result from these operations? Assume that the initial value of Buf_Size is 6.
The idea here is that the add and subtract operations are not atomic, and could be interrupted in mid-operation, when the other task could then run. If A runs to completion, then B runs to completion, Buf_Size has the value 7 (6 + 2 – 1). Similarly if B runs to completion then A runs to completion. If A or B get interrupted in the middle of adding or subtracting, then whichever task finishes last will determine the value in Buf_Size. If A runs but is interrupted after it fetches Buf_Size but before it stores the modified value (allowing B to fetch Buf_Size), or if B runs first and is interrupted after the fetch but before the store, allowing A to fetch Buf_Size, then if A finishes last Buf_Size will have value 8, and if B finishes last Buf_Size will have value 5.


7. Compare the Java competition synchronization mechanism with that of Ada.
Java methods (but not constructors) can be specified to be synchronized. A synchronized method called through a specific object must complete its execu- tion before any other synchronized method can run on that object. Competition synchronization on an object is implemented by specifying that the methods that access shared data are synchronized.
The competition synchronization mechanism of the Ada Language is intended to provide a facility for tasks to synchronize their actions. Accept and select statements are the two main features of the language that deal with the issue of synchronization This paper points out one major problem that arises in connection with these features and proposes a possible solution to it.


8. Compare the Java cooperation synchronization mechanism with that of Ada.
Cooperation synchronization in Java is implemented with the wait, notify, and notifyAll methods, all of which are defined in Object, the root class of all Java classes. All classes except Object inherit these methods. Every object has a wait list of all of the threads that have called wait on the object.
In Ada, cooperation synchronization is required between two tasks that when the second task must wait for the first task to finish executing before it may proceed.


9. What happens if a monitor procedure calls another procedure in the same monitor?
Because the access mechanisms are part of the monitor, implementation of a monitor can be made to guarantee synchro- nized access by allowing only one access at a time. Calls to monitor procedures are implicitly blocked and stored in a queue if the monitor is busy at the time of the call.


10. Explain the relative safety of cooperation synchronization using semaphores and using Ada’s when clauses in tasks.
As soon as we start using concurrent threads, we need to think about various issues that fall under the broad description of thread safety. Generally, we need to take steps to make sure that different threads don't interact in negative ways:
-if one thread is operating on some data or structure, we don't want another thread to simultaneously operate on that same data/structure and corrupt the results;
-when Thread A writes to a variable that Thread B accesses, we need to make sure that Thread B will actually see the value written by Thread A;

-we don't want one thread to hog, take or lock for too long a resource that other threads need in order to make progress.

3 comments: