Lecture 9- Synchronization Flashcards

1
Q

What is Simulation of shared memory?

A
Create a Java class.
 Pass a variable of this class to each of the involved threads.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Synchronization?

A

All the mechanism of separate access to a shared resource can be implemented in Java.

However, Java has its own mechanism: calling a function
synchronized.

The class simulating the sharing memory can have one or more functions accessing the date declared as synchronized.

This ensures that at the given moment of time only one
thread can be inside a synchronized function.

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

Explain Waiting and notification in Java?

A

The functions described below can be performed in a
synchronized function of the given class.
wait() the current thread blocks itself and waits somebody to notify it.
notify() releases one of the waiting threads.
notifyAll() releases all of the waiting threads.

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

What are the problems with Peterson’s Solution?

A

The entry/exit protocols are directly programmed using busy-waiting

Busy-waiting protocols are difficult to design, understand,
generalise, and analyse

There is no clear separation between variables used for
synchronisation and those for computing results

They are error-prone and inefficient

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

What are the Motivation for Semaphores?

A

Interprocess synchronisation is fundamental to concurrent programming

It is desirable to have special tools that can aid in the design of correct synchronisation protocols

Nice to write entry/exit protocols by single statements
WAIT;
critical section;
SIGNAL;
non-critical section

We should allow the processor being switched from a blocked process to another process

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

What is the definition of Semaphore?

A

Semaphores were introduced by Dijkstra (1968)
A semaphore is an integer variable that takes only non-negative values

Only two operations are permitted on a semaphore s:
P(s) (Passeren – to pass s):
If s > 0 then decrement s
else block the calling process
V(s) (Vrijgeven – to release s):
If processes blocked on s then unblock one
else increment s

Semaphores are implemented efficiently with hardware facilities and in the kernel of OSs by block-waiting

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

What is the behaviour of the FIFO Buffer

A

We need NextIn and NextOut to locate where to place an item into and take an item from the buffer

NextIn and NextOut are incremented one by one. When they reach the end of the buffer we need reset them to 0 (the head of the buffer)

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

What is the summary?

A

Semaphore is a primitive to synchronise threads

A semaphore has P() and V() operations to guarantee mutual exclusion of threads relevant to one shared object

Demonstrated the application of semaphores for the Producer and Consumer problem

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