Kamis, 27 Juni 2013

Chap 13 - Review Question and Problem Set - Concepts of Programming Languages, Sebesta

CONCEPTS OF
PROGRAMMING LANGUAGES
TENTH EDITION
Robert W. Sebesta
Chapter 13-Concurrency


Review question

1. What are the three possible levels of concurrency in programs?
Answer:
- Instruction level (executing two or more machine instructions simultaneously)
- Statement level (executing two or more high-level language statements simultaneously)
- Unit level (executing two or more subprogram units simultaneously)

2. Describe the logical architecture of an SIMD computer.
Answer:
SIMD computer has some processor. One processor is used to control and coordinate the other processor. ecause all of the processors, except the controller, execute the same instruction at the same time, no synchronization is required in the software. Perhaps the most widely used
SIMD machines are a category of machines called vector processors. They 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. However, SIMD processors are now used for a variety of application areas, among them graphics and video processing. Until recently, most supercomputers were vector processors.

4. What level of program concurrency is best supported by SIMD computers?
Answer: Statement-level concurrency

5. What level of program concurrency is best supported by SIMD computers?
Answer: Unit-level concurrency

7. What is the difference between physical and logical concurrency?
Answer: Physical concurrency is several program units from the same program that literally execute simultaneously.Logical concurrency is multiple processors providing actual concurrency, when in fact the actual execution of programs is taking place in interleaved fashion on a single processor.

8. what is the work of a scheduler?
Answer: A run-time system program called a scheduler manages the sharing of processors among the tasks.

16. What is a task descriptor?
Answer: Task descriptor is a data structure that stores all of the relevant information about the execution state of a task.

21. What is a binary semaphore? What is a counting semaphore?
Answer: Binary semaphore is a semaphore that requires only a binary-valued counter, like the one used to provide competition synchronization. A counting semaphore is a synchronization object that can have an arbitrarily large number of states.

30. What is purpose of an Ada terminate clause?
Answer: The purpose of an Ada terminate clause is to mark that the task is finished with its job but is not yet terminated.

34. What does the Java sleep method do?
Answer: It blocks the tread by using a single parameter that contains of integer of millisecond

35. What does the Java yield method do?
Answer: Yield method surrenders the processor voluntarily as a request from the running thread.

36. What does the Java join method do?
Answer: Java forces a method to delay its execution until the run method of another thread has completed its execution.

42. What kind of Java object is a monitor?
Answer: In Java, a monitor can be implemented in a class designed as an abstract data type, with the shared data being the type. Accesses to objects of the class are controlled by adding the synchronized modifier to the access methods.

55. What is Concurrent ML?
Answer: Concurrent ML is an extension to ML that includes a fform of threads and a form of synchronous message passing to support concurrency.

56. What is the use of the spawn primitive of CML?
Answer: The use of Spawn primitive of CML is to create a thread.



57. What is the use of subprograms BeginInvoke and EndInvoke in F#?
Answer: The use of subprograms BeginInvoke and Endinvoke in F# is to call threads asynchronously.



58. What is the use of the DISTRIBUTE and ALIGN specification of HPC?
Answer: The use of DISTRIBUTE and ALIGN specification of HPC is to provide information to the compiler on machines that do not share memory, that is, each processor has its own memory.


Problem set

1 . Explain why a race condition can create problems for a system.
Answer:
Race condition is a condition when two or more task is racing to use the shared resource. This condition may create a problem for the system because when there is no "winner" so the system have choose which task can may use the resource. But as long as there is a task arrives first the system will allow it to use the resource.

2. What are the different ways to handle deadlock?
Answer:
To handle a deadlock the system should terminated one or more program units, the others may continue without being terminated. In other case of deadlock, the system can pending one or more program units and let the other continue.

3. Busy waiting is a method whereby a task waits for a given event by continuously checking for that event to occur. What is the main problem with this approach?
Answer:
The main problem with busy waiting is that machine cycles are wasted in the process

4. In the producer-consumer example of Section 13.3, suppose that we incorrectly replaced the release(access) in the consumer process with wait(access). What woud be the result of this error on execution of the system?
Answer:
Deadlock would occur if the release(access) were replaced by a wait(access) in the consumer process, because instead of relinquishing access control, the consumer would wait for control that it already had.


Special thanks to Mr. Tri Djoko Wahjono, Ir., M.Sc.

Tidak ada komentar:

Posting Komentar