nav

       HOME    BINUS EVENT   HOW TO   KBP   THOUGHTS

About



Thursday, January 29, 2015

Assignment #13

Source:
Concepts of Programming Languages, Robert W. Sebesta.
Chapter 13: Concurrency, page 625-628

By:
Name : Helena Natanael
NIM  : 1801380333




Review Question:

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 is a multiple independent processors (multiple threads of control). While logical concurrency is 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?
They are called quasi-concurrent because they have a single thread of control.

10. What is a multithreaded program?

A multi-threaded program is a program designed to have more than one thread of control.


Problem Sets:

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 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.
In Java, cooperation synchronization  is implemented with the wait, notify, and notify. All methods, all of which are defined in Object, the root class of all Java classes. Every object has a wait list of all of the threads that have called wait on the object. While 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?
Implementation of a monitor can be made to guarantee synchronized 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.
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.

No comments:

Post a Comment