Week 11-12: OOP concurrency Flashcards
How does C++ manage object allocation and deallocation?
In C++, objects can be static, stack-dynamic, or heap-dynamic. Deallocation is explicit using new and delete. Constructors and destructors are implicitly called.
What is the purpose of access controls in C++ and what are the different types?
Access controls in C++ manage visibility and inheritance of class members. The types are:
Private: visible only within the class and friends.
Protected: visible within the class and subclasses.
Public: visible to all.
Explain the difference between public and private derivation in C++.
Public derivation makes inherited public and protected members also public and protected in the subclass. Private derivation makes inherited public and protected members private in the subclass, breaking the “is-a” relationship.
Describe dynamic binding in C++ and its relation to virtual functions.
In C++, virtual methods can be called through polymorphic variables and are dynamically bound to messages. Pure virtual functions have no definition and make a class abstract. If a subclass does not redefine a pure virtual function, it remains an abstract class.
How does C++ handle multiple inheritance and what are potential issues?
C++ supports multiple inheritance, and inherited members with the same name can be accessed using the scope resolution operator (::). Potential issues include complexity and the possibility of name collisions.
What is a Class Instance Record (CIR) in OOP?
A Class Instance Record (CIR) stores the state of an object, built at compile time, with each class having its own CIR. For subclasses, their instance variables are added to the parent class’s CIR.
How are instance variables accessed efficiently in a CIR?
Instance variables in a CIR are accessed using constant offsets from the beginning of the CIR instance, making the access efficient.
What is the purpose of virtual method tables (vtable) in dynamic binding?
Virtual method tables (vtable) store pointers to the methods that will be dynamically bound. These pointers are set at object creation time and allow method calls to be connected to the corresponding code.
What are the four levels at which concurrency can occur?
Concurrency can occur at the machine instruction level, high-level language statement level, unit level, and program level.
What is the difference between heavyweight and lightweight tasks?
Heavyweight tasks execute in their own address space, while lightweight tasks run in the same address space and are more efficient.
What are the two kinds of synchronization required when tasks share data?
The two kinds of synchronization are cooperation synchronization, where one task waits for another to complete a specific activity, and competition synchronization, where tasks compete for resources that cannot be simultaneously used.
What are the possible states of task execution?
The possible states of task execution are new, ready, running, blocked, and dead.
What is a race condition, and how can it affect task execution?
A race condition occurs when the outcome of task execution depends on the non-deterministic timing of certain operations, leading to unpredictable results.
What is deadlock in a concurrent environment?
Deadlock occurs when all tasks in a concurrent environment lose their liveness and cannot proceed, threatening the reliability of a program.
Name three methods for providing mutually exclusive access to a shared resource.
Semaphores, monitors, and message passing are three methods for providing mutually exclusive access to a shared resource.