Sunday, June 16, 2013

Concepts of Programming Languages – Chapter 13


Review Question

1. What are the three possible levels of concurrency in programs?
- 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)

7. What is the difference between physical and logical concurrency?
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?
Scheduler manages the sharing of processors among the tasks.

12. What is a heavyweight task? What is a lightweight task?
Heavyweight task executes in its own address space. Lightweight task all run in the same address space.

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

18. What is the purpose of a task-ready queue?
The purpose of a task-ready queue is to be storage of tasks that are ready to run.

21. What is a binary semaphore? What is a counting semaphore?
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?
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?
Sleep method blocks the the thread.

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

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

37. What does the Java interrupt method do?
Interrupt becomes one way to communicate to a thread that it should stop.

55. What is Concurrent ML?
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?
The use of Spawn primitive of CML is to create a thread.

57. What is the use of subprograms BeginInvoke and EndInvoke in F#?
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?
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 clearly why a race condition can create problems for a system.
Because two or more tasks are racing to use the shared resource and the behavior of the program depends on which task arrives first (and wins the race). The importance of competition synchronization should now be clear.

2. What are the different ways to handle deadlock?
- Ignoring deadlock
- Detection
- Prevention
- Avoidance

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?
Busy-waiting or spinning is a technique in which a process repeatedly checks to see if a condition is true, such as whether keyboard input or a lock is available.
Spinning can also be used to generate an arbitrary time delay, a technique that was necessary on systems that lacked a method of waiting a specific length of time.
Processor speeds vary greatly from computer to computer, especially as some processors are designed to dynamically adjust speed based on external factors, such as the load on the operating system.
Busy waiting may loop forever and it may cause a computer freezing.

No comments:

Post a Comment