Concurrency 1 Flashcards

1
Q

Explain the difference between multi-tasking and multi-threading…

A

Multi-tasking is the concurrent running of processes on a machine.
Multi-threading is the concurrent running of threads of execution over a program.

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

What makes multi-tasking expensive?

A

Context switching is needed whenever a core changes processes.

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

Why does multi-threading have less overhead than multi-tasking?

A
  • All threads share the same address space.
  • All threads share the same process.
  • Threads can communicate with each other easily.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the main issue that multi-threading solves?

A

Idle time - Singular threading may lead to the CPU having idle time while waiting for operations to complete, for example, IO operations. Multi-threading enables other threads to continue other processes whilst waiting. This ensures efficient use of idle time.

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

Define Multi-tasking

A

Enables the CPU to perform multiple processes at once. Processes are assigned to cores. This is what enables systems to run multiple programs at any given time.

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

Define Non-Determinism… Why are multi-threaded programs non-deterministic?

A

From a flow of execution point of view, each time the multi-threaded program is run, a different output is given. In multi-threading, the sequence of execution is decided by the CPU running the threads. Thus, in a non-deterministic way.

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

Define Deterministic

A

The situation in which a program has a execution flow in which each method depends on an input from another method in a sequential way.

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

Define the race condition?

A

The situation in which multiple threads are reading from and writing to a shared resource simultaneously. This can lead to data inconsistency due to Thread A reading the value whilst Thread B writes an update value. Thus, Thread A now has incorrect data.

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

Why does the race condition occur?

A

Because all threads of a program share the same memory address space.

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

What is the solution to Race Condition?

A

Use the synchronised keyword. This locks the object that the thread is executing over, thus meaning only one thread can be running on the object. This can be used to prevent multiple threads operating on a shared resource.

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

Define cache incoherence…

A

When multiple threads pull the same value from main memory, and all operate on it independently before assigning it back to memory. Thus, all threads will be assigning different values back to the same variable.

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

What is the solution to cache incoherence?

A

Using the volatile keyword on a variable. This ensures that when the variable is modified, it is done so consistently across the program, and not just locally for that thread.

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

Define Atomic Actions

A

An Atomic Action is one that has no middle section of execution. Operations are either completed entirely, or not started.

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

Why are Atomic Actions useful?

A

They make it impossible for data inconsistency to occur.

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

Define Non-determinism…

A

A feature of multi-threading in which the OS determines the order of tasks being executed via a complex scheduling algorithm. As programmers, we don’t have much control (unless thread management is used).

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

Define Liveness…

A

Concerns whether we can get the correct results in time i.e eventually. For example, avoid thread issues such as dead lock.

17
Q

Define Correctness

A

Concerns the correctness of the program.