Week 11-12: OOP concurrency Flashcards

1
Q

How does C++ manage object allocation and deallocation?

A

In C++, objects can be static, stack-dynamic, or heap-dynamic. Deallocation is explicit using new and delete. Constructors and destructors are implicitly called.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of access controls in C++ and what are the different types?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain the difference between public and private derivation in C++.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe dynamic binding in C++ and its relation to virtual functions.

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does C++ handle multiple inheritance and what are potential issues?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a Class Instance Record (CIR) in OOP?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How are instance variables accessed efficiently in a CIR?

A

Instance variables in a CIR are accessed using constant offsets from the beginning of the CIR instance, making the access efficient.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the purpose of virtual method tables (vtable) in dynamic binding?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the four levels at which concurrency can occur?

A

Concurrency can occur at the machine instruction level, high-level language statement level, unit level, and program level.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the difference between heavyweight and lightweight tasks?

A

Heavyweight tasks execute in their own address space, while lightweight tasks run in the same address space and are more efficient.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the two kinds of synchronization required when tasks share data?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the possible states of task execution?

A

The possible states of task execution are new, ready, running, blocked, and dead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a race condition, and how can it affect task execution?

A

A race condition occurs when the outcome of task execution depends on the non-deterministic timing of certain operations, leading to unpredictable results.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is deadlock in a concurrent environment?

A

Deadlock occurs when all tasks in a concurrent environment lose their liveness and cannot proceed, threatening the reliability of a program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Name three methods for providing mutually exclusive access to a shared resource.

A

Semaphores, monitors, and message passing are three methods for providing mutually exclusive access to a shared resource.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly