Concurrency Flashcards

1
Q

What is interference?

A

Interference may occur when multiple threads try to modify shared
variables at approximately the same time (thus they need to share the same data
memory to do this)

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

What is an OS process

A

The student should probably draw a diagram how a computer has a number of OS
processes, the JVM runs in one of these processes, and this JVM can then support a
number of individual threads [1 mark]. The OS process is allocated independent
resources such as it own memory space for machine code, stack and data, thus
each process runs a different executable [1 mark]

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

What is synchronization?

A

This can be eliminated by synchronizing critical
sections of the code that modify the shared variables [1 mark] – this only permits
one thread access to the shared variables at a time within a critical section [1
mark]. The synchronization mechanism uses locking where only one thread at a
time can have the lock

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

Intrinsic Lock

A

The thread will get the lock at the start of the
critical section of code and give it back at the end, thus only allowing a single
thread to run in the critical section [1 mark].

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

What is the concurrency abstraction?

A

Based on having a number of processes, the abstraction models the overall system by interleaving the execution of atomic atoms of processes.

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

What is a abstract process?

A

Totally ordered sequence of atomic atoms.

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

What is a sequential program in the concurrency abstraction?

A

Consists of single process. assuming a fixed input, program is deterministic

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

What is a concurrent program in regards to the concurrency abstraction?

A

Consists of two or more processes carrying out atomic actions

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

What is an atomic action?

A

No divisible in terms of processing

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

What is interleaving?

A

describe a MODEL in which atomic actions from different processes are carried out.

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

Do atomic actions get carried out simultaneously?

A

No, in the concurrency abstraction they are interleaved.

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

Is a++ an atomic action?

A

No, consists of a LW a SW and a addi

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

What is a context switch?

A

When the OS moves from processing one process to the a different process

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

What is an OS process?

A

Used to run separate tasks which do not interfere with each other, each process has its own virtual memory address space for executable machine code, data, and stack

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

How are threads and OS processes different?

A

Threads share the same address space, thus share the same code

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

Draw the OS processes, JVM and Java Threads

A

DRAW IT

17
Q

What does the JVM do?

A

Runs a single process on top of the OS, allows spawning of threads of execution

18
Q

What does a thread have its own copy of?

A

Program counter register for its location in the running program
Other registers fro local variables being worked upon
Stack space for procedure call parameters and other local variables

19
Q

When does context switching occur?

A

Happens while thread code is being executed.

20
Q

What are the 6 different states of a thread?

A

NEW
A thread that has not yet started is in this state.
RUNNABLE
A thread executing in the Java virtual machine is in this state.
BLOCKED
A thread that is blocked waiting for a monitor lock is in this state.
WAITING
A thread that is waiting indefinitely for another thread to perform a
particular action is in this state.
TIMED_WAITING
A thread that is waiting for another thread to perform an action for up
to a specified waiting time is in this state.
TERMINATED
A thread that has exited is in this state.

21
Q

Draw the thread lifecycle

A

DRAW IT

22
Q

What does race condition refer to?

A

Indicate bad effects resulting from unfortunate thread timings

23
Q

Define interference

A

Destructive update caused by arbitrary interleaving of read write actions.

24
Q

What can make a method mutually exclusive?

A

Syncronized

25
Q

Describe a synchronized methoed

A

Method locks the object whose method has been called, other threads cannot enter other synchronised methods on the same object

26
Q

What is a reentrant lock?

A

Java runtime system allows a thread to reacquire the lock that it already holds, eliminates possibility of a single thread deadlocking itself.

27
Q

How is the lock implemented?

A

Spinlocks. 0 if unlocked 1 if locked. To lock a thread while(spinlock_mem != 0){;}
spinlock_mem = 1;

28
Q

How to we prevent interference?

A

Critical sections of code need to synchronized.

29
Q

What does safely published mean?

A

Both the reference to the object and the objects latest state will be made visible to other threads at the same time.

30
Q

What are the 4 ways to safely publish an object?

A

Initialise the object reference as a static initialiser
Storing reference to it in a volatile field
Storing a reference to it into a final field.
Storing a reference to it is properly guarded by a lock