Exam 2 Flashcards

1
Q

The bare minimum number of cores and CPUs that are required to run a multithreaded program is…

A

One CPU with one core.

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

Calling the join() method on a running thread causes…

A

The join call blocks

Waiting for the thread to finish

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

If a thread has already finished running, then calling the join() method on the thread causes…

A

The thread is terminated normally without any issues.

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

When a thread is waiting to enter a critical section using a std::lock_guard, its CPU usage will be…

A

0%.

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

Given eight independent, shared resources, the optimal number of mutexes to maximize concurrent, thread-safe access to the eight resources is…

A

8.

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

A multithreaded program has four threads that run in parallel on four core machine. Each thread runs for two minutes. The total run time of the program would be…

A

Two minutes.

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

In order to use two resources protected by two mutexes m1 and m2, the preferred order of locking the mutex would be…

A

std::lock(m1, m2);

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

The most suitable command to copy a file named test.txt from a server named bkup.org would be…

A

scp bkup.org:test.txt

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

Given a C++ source file named exam2.cpp, the executable generated by compiling it must be named…

A

The executable can have any name.

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

The following C++ statement…

std::string a[] =
{“1”, “2”, “3”, “4”, “5”};

A

Creates an array of five string objects.

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

The minimum number of cores that are required to run a process with four threads (ignoring performance issues) would be…

A

One.

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

The minimum number of threads that are present in a standard process created by modern operating systems would be…

A

One.

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

The number of mutexes that are necessary to ensure MT-safe access to the SharedValue shown in the code fragment below would be…

const std::string
SharedValue = “12345”;

void threadMain() {
    // Code here
}
A

Zero.

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

Which of the following resources are not shared between multiple threads…

A

CPU Registers.

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

Given an eight core CPU, the maximum number of threads that can be created in a single process is limited to…

A

Depends on the maximum threads supported by the Operating System.

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

When the get() method is called on a std::future object, the get() method…

A

The call blocks until the future value is set without waiting on thread.

17
Q

An std::atomic enables fast mutexes because…

A

Atomics use special CPU instructions.

18
Q

The correct reference to a text file named test.txt in the parent directory is…

A

std::ifstream input(“../test.txt”);