Computer Fundamentals - Engineering

Q1:

A program component that allows structuring of a program in an unusual way is known as

A Correlation

B Coroutine

C Diagonalization

D Quene

E None of the above

ANS:B - Coroutine

An ideal subroutine is a mathematical function; it takes inputs and returns the results of its computation. It has a single entry point and all data local to it is initialized upon entry and cleaned up when it returns to the caller. The next call, if any, starts all over again and no local residues are carried over from the last invocation.

A coroutine, is an interesting deviation from these conventions. It can yield control back to the caller as soon as there are partial results that can be put to use. Moreover, when invoked again, it can resume the computation from where it left. These yield/resume semantics make coroutines a better unit of structuring programs for certain types of problems.