Thursday, June 27, 2013

Concepts of Programming Languages Chapter 13


Concepts of Programming Languages Chapter 13


Name            : Erland
NIM              : 1601218035
Lecturer       : Tri Djoko Wahjono, Ir., M.Sc. (D0206)
Assignment  : Concept of programming languages Chapter 13

Review Questions


       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 : 
In an SIMD computer, each processor has its own local memory. One processor controls the operation of the other processors. Because 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 usedSIMD 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.
       3. Describe the logical architecture of an MIMD computer.
             Answer :
Computers that have multiple processors that operate independently but whose operations can be synchronized are called Multiple-Instruction Multiple- Data (MIMD) computers. Each processor in an MIMD computer executes its own instruction stream. MIMD computers can appear in two distinct configurations: distributed and shared memory systems. The distributed MIMD machines, in which each processor has its own memory, can be either built in a single chassis or distributed, perhaps over a large area. The shared-memory MIMD machines obviously must provide some means of synchronization to prevent memory access clashes. Even distributed MIMD machines require synchronization to operate together on single programs. MIMD computers, which are more general than SIMD computers, support unit-level concurrency. The primary focus of this chapter is on language design for shared memory MIMD computers, which are often calledmultiprocessors.
      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 MIMD computers?
             Answer : 
Unit-level concurrency is best supported by MIMD computers.
       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:
Scheduler manages the sharing of processors among the tasks.

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

       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 : 
A binary semaphore is  a semaphore that requires only a binary-valued counter. A counting semaphore is a synchronization object that can have an arbitrarily large 
       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 :
Sleep method blocks the the thread.
       35. what does the Java yield method do?
             Answer :
The yield method, which takes no parameters, is a request from the running thread to surrender the processor voluntarily. The thread is put immediately in the task-ready queue, making it ready to run. The scheduler then chooses the highest-priority thread from the task-ready queue. If there are no other ready threads with priority higher than the one that just yielded the processor, it may also be the next thread to get the processor.
      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.

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

       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.
      47. How are explicit locks supported in Java?
             Answer :
Java 5.0 introduced explicit locks as an alternative to synchronized method and blocks, which provide implicit locks. The Lock interface declares the lock, unlock, and tryLock methods. The predefined ReentrantLock class implements the Lock interface. To lock a block of code, the following idiom can be used:Lock lock = new ReentrantLock();. . .Lock.lock();try {// The code that accesses the shared data} finally {Lock.unlock();}
      48. What kinds of methods can run in a C# thread?
             Answer :
Rather than just methods named run, as in Java, any C# method can run in its own thread.
      55. What is Concurrent ML?
             Answer :
Concurrent ML (CML) is an extension to ML that includes a form of threads and a form of synchronous message passing to support concurrency. The language is completely described in Reppy (1999).
      56. What is the use of the spawn primitive of CML?
             Answer :
The use of Spawn primitive of CML is to create a thread.