Lecture 7 - Concurrency and Synchronisation 1 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is concurrency?

A

Multiple or things being executed at the same time

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

What is the difference between real and simulated (apparent) concurrency?

A

Real concurrency: multiple CPUs genuinely executing things at the same time

Apparent concurrence: one CPU using scheduling to give the illusion of concurrency

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

What is the benefit of concurrency?

A

Increases performance

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

What is the downside to concurrency?

A

Not all resources can be accessed by multiple threads at the same time

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

When is mutual exclusion needed?

A

When some resource can only be used by one thread at a time

E.g. shared memory structures, files, …

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

When must synchronisation be used?

A

When multiple threads want to access the same object at the same time - critical sections

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

What are the 4 conditions to provide mutual exclusion?

A

No two processes can simultaneously be in critical section

No assumptions made about speeds or numbers of cpus

No process running outside its critical sections may block another process

No process must wait forever to enter its critical region

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

Only critical regions that access __________ need to synchronize with each other

A

The same resource

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

Synchronisation for threads has the same pattern. What is it?

A

Attempt to enter critical section

Do stuff in critical section

Exit critical section

Do all non critical stuff

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

How does strict alternation work to protect critical sections?

Whats the problem with it?

A

Use a shared variable to indicate which thread/process is currently in critical section

Avoids race conditions but can just get stuck

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

How does the Bakery algorithm work to protect critical sections?

A

Before entering critical section, process receives a number

Numbering scheme always generates numbers in increasing order

Holder of smallest number enters critical section

If two processes receive same number, lower pid is served first

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

How do locks work?

A

Create a lock associated with shared resource

Lock can be locked or unlocked:

locked - some thread is accessing the resource

Unlocked - not held by any thread

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

How do locks prevent race conditions?

A

Allow only one thread at a time to use the shared item

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

Whats the problem with locks?

A

Can reduce concurrency - may have several threads waiting for the one shared resource to become available

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

What are the expected API operations of a lock?

A

Create new lock

Lock a lock

Unlock a lock

Declare variable as lock

Possibly:

Test if lock is lockable

Destroy lock to reclaim memory

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

Can critical sections be used for syncing between processes?

A

no

17
Q

What are the lock operations in the posix api?

A

pthread_mutex_init

pthread_mutex_lock

pthread_mutex_unlock

pthread_mutex_destroy

18
Q

What is a spinlock?

A

Thread can lock the lock variable if it is unlocked

If not, sits in an infinite loop testing the variable until it becomes unlocked

19
Q

What is the time of check to time of use problem?

A

Where locks are interrupted between testing the variable and settting the variable if it was unlocked. I.e. race condition on the lock itself

20
Q

why does a spinlock need hardware support?

How does the hardware support work?

A

Checking if lock is locked and locking it needs to be atomic

1 = unlocked, 0 = locked

put 0 in a register, then exchange that register with the lock (atomic)

if register now contains 0 it was already locked - keep trying again

if register now contains 1 it was unlocked and is now locked