Synchronisation Flashcards

1
Q

What is conditional synchronisation?

A

Threads only execute or continue to run if condition has been met, usually when it has been notified by another thread.

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

What is mutual exclusion?

A

A thread is able to gain a mutex (mutually exclusive lock) to ensure it will keep synchronised access to the method or block.
Similar to an atomic action

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

What is the lost deposit problem?

A

Due to no synchronisation, money can be deposited (or withdrawn) twice, and the final balance will get overwritten by one of the threads without taking account of the other’s actions.

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

What are locks?

A

Only one thread can get a lock on a synchronised method or block at a time.
If two thread attempt to get a lock, one will succeed and the other will fail, resulting in having to wait
Java creates locks for each object
With a synchronised method, a thread must obtain a lock before executing the method statements

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

What are synchronised methods?

A

Used with classes to ensure atomic actions and that only one thread can access at any one time

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

What are synchronised blocks?

A

Block of code within a method can also be synchronised.

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

What is the issue with synchronised blocks?

A

Difficult to maintain a record of across code

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

What is the ‘wait’ used for in Conditional Synchronisation?

A

To enable waiting until a notify has been sent from another thread

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

What is the ‘notify’ used for in Conditional Synchronisation?

A

To inform the waiting thread that the wait is over and that they should be able to proceed with their function.

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

What is the ornamental garden example?

A

Two entrances, want to count total of who came in and from which entrance.
Needs to be synchronised addVisitor method to get the correct total number of visitors

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

What is deadlock?

A

Where no threads are ever able to get access to required resources.
Example: 2 threads, 2 objects with locks, can create deadlock as each object is always waiting on the other.

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

What is starvation?

A

When resources are allocated but some threads never get access.

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