Thread Interaction Flashcards

1
Q

Where does thread interaction operations occur at?

A

They occur at the OS Kernel level. They are second important functional area of a OS microkernel beside thread management.

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

What are the types of interactions between threads and the relation between them? Where is the interaction object located?

A

Communication, Cooperation and Coordination.
Both communication and cooperation require coordination (in time) between threads.

The interaction object may be located at the source thread (sender), target thread (receiver) or between the threads.

An interaction may include more than two threads and more than one interaction object.

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

Describe the concept of coordination in relation to mutual exclusion?

A

Coordination at the kernel level requires mutual exclusion since coordinating threads are accessing critical sections which need to be reserved/protected to be safe (accessing shared data in the kernel level).

Here we deal with coordination outside the kernel level.

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

What is signaling? its goal and what kernel OPs allow for it?

A

The goal of signaling is to establish a temporal order of activities.

Section A in thread T1 is to be executed prior to a section B in another thread T2. When section A in thread T1 is done executing, a signal is sent for which thread T2 is waiting and it can then start executing its section B.

Kernel OPs signal (at T1) and wait (busy waiting at T2) that use a shared binary variable s allow for signaling between threads.

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

What mutual synchronization?

A

It is when two threads T1 and T2 wait for each at one execution point. It is equivalent to two signal and wait operations.

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

What is group signaling? What are the two types of it?

A

Group signaling is when more than 2 threads are participating in a signaling operation.

AND-Signaling: A thread is allowed to proceed only when several threads have sent a signal (AND-OP at signal side)
AND-Wait: Several threads wait for a signal from another thread (AND-operation at wait side)
AND-Signaling-Wait: Multiple threads are waiting for all other multiple threads to send a signal.

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

What is signaling with buffering?

A

n:1 signaling: Many threads may deposit signals at a signaling object. A waiting thread is deblocked if at least one signal is stored.

1:m signaling: Many threads may wait at a signaling object. When a signal arrives, one of the waiting threads (for example, the first one) is deblocked.

Both cases combined lead to arbitrary n:m relations. Here we have a queue of waiting threads in which we add blocked threads on the wait call and increase the count and then deblock the first waiting thread in the queue and decrease count on signal sent. The capacity initial value is what determines the n:m signaling relation.

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

What is mutual group synchronization?

A

All threads synchronize mutually at the same point. The threads may continue only when all other threads have reached the same synchronization point.

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

What are locks?

A

Used to secure critical sections for mutually exclusive executions in two threads. Using the OPs lock and unlcok to set/reset a variable set. The first thread that calls lock(s) continues its execution and sets the s variable while the second thread that calls lock(s) gets blocked and only deblocked when the first thread calls unlock(s) after finishing executing its critical section.

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

Describe the structure of a channel object, its parameters and operations, and describe the implementation depending on the order of sending/receiving and what are the variants of this message transfer. What type of communication is this?

A

A channel is a data object that provides send and receive OPs.
It has the name of the channel object (CO) and the address of the message buffer to send and address where the received message should be written.
OPs: send(CO, buffer_send), receive(CO, buffer_receive)

  • First send, then receive: msg is stored in CO and can be retrieved later in the receive OP (by copying msg in the receive buffer).
  • First receive, then send: receive buffer address is stored on receiver thread, send OP later copies the message to that address.

Variants of the message transfer include:
- By value: msg itself is buffered in the channel (two copy OPs)
- By reference: the address of the message is buffered in the channel (one copy OP)

Since sender and receiver do not wait for their communication partner, this is called asynchronous communication.

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

What are the 4 types of coordinated communication?

A
  • Async send / Async receive: receiver and sender do not wait for each other.
  • Async send / Sync receive: receiver is blocked until the sender sends the message
  • Sync send / Async receive: sender sends message and is blocked until the receiver retrieves it
  • Sync send / Sync Receive: Mutual sync where both sender and receiver are blocked and wait for receiving / sending the message respectively.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is polling/probing in terms of sending/receiving a message?

A

It is with a async send and on the receiver end, when it calls receive, if there is a message it takes it (copy), if not, it just continues its normal execution.

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

Describe how to achieve the ability to buffer more than one message then the ability to buffer many receive operations? How to adapt the data structures for this purpose and what problem may arise?

A
  • Buffer more than one message: Many threads send messages to a central server thread through a n:1 channel object.
  • Buffer many receive operations: One thread sends a message to a 1:n channel object with a server consisting of many replicated threads with receive requests the from the shared 1:n channel
  • Many messages and many receivers: Combine both solutions

The channel object data structure must include a queue for waiting senders, queue for stored messages, queue for waiting receivers, queue for stored target buffer addresses depending on the use case. The capacity of the channel object can be unlimited (requires dynamic memory management) or limited (requires mechanisms for overflow by overwritting, refusing OP or blocking until capacity is available again depending on the application).

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

Describe how to physically assign a channel object to a specific thread?

A

When channel objects are statically/physically assigned to a thread. It can be done at either sides:
- Sender thread owns the channel to deposit all outgoing messages, in this case it is called an exit port. Exit ports are 1:n.
- Receiver thread owns the channel from which it receives all messages, it is called an entry port. Entry ports are n:1 channels. They are the most commonly used communication objects in today’s OSs.

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

Describe group communication and its variants.

A

-In one-to-one channel communication (single cast), we have one thread sending a message which is received by exactly one other thread.

  • In one-to-many channel communication (broadcast, multicast, replication), we have a thread that sends identical messages to many receiver threads in one operation.
  • In many-to-one channel communication (combination), we have many threads sending messages to one receiver thread that receives a combination of the messages in one operation.
  • many-to-many channel communication (all-to-all broadcast): we have a combination of both of the above.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the types of combination in a many-to-one channel communication?

A
  • Concatenation
  • Logical Operation (&, |)
  • Arithmetic Operation (sum)
16
Q

Describe the concept of cooperation between threads? What is a cooperation section?

A

Cooperation between threads is how threads handle executing and accessing sharing data to prevent errors and inconsistencies.

A cooperation section is a section that at any time one thread is executing it.

17
Q

How to solve the problem of two threads working on shared data?

A

Define it critical section and put it under mutual exclusion using locks for example.

18
Q

What is a monitor? And what is its advantage in comparison to a lock? How is it used?

A

A monitor is an object that guarantees mutual exclusion without requiring the programmer to explicitly insert lock and unlock operations .

It consists of procedures and data structures that at any time ensures it is used by not more than one thread. In fact the microkernel of an OS with a global kernel lock is nothing else but a monitor.

The use of simple locks is error-prone. In some cases, the use of locks can lead to mutual blocking (deadlock). See bounded buffer example in 05_interaction slides 50, 51.

To solve this problem, the monitor offers the concept of a condition variable:
- cwait(c): thread releases monitor and wait for the subsequent csignal(c) (fullfilment of condition c), after that it continues in the monitor.
- csignal(c): a waiting thread is deblocked, the monitor is occupied again. If there is no thread waiting, procedure is void.
Waiting threads in a monitor are managed with a queue.
See bounded buffer example in 05_interaction slides 52, 53, 54. Here we define two conditions for buffer not full and buffer not empty.

19
Q

What cooperation with bounded capacity? How to achieve it?

A

It is expanding the cooperation section to allow more than one thread to concurrently execute the section.

It can be achieved by modifying the lock/unlock operations by using a counter instead of a binary variable.

An example is the Reader-Writer cooperation where in the cooperation section we have at most 1 writer but any arbitrary number of readers because read access are harmless and do not need to run under mutual exclusion. When there is at least one writer, no other writer or reader can have access. Otherwise reader can have access to read and the next writer thread must wait for all other reads/write to finish before gaining access. This can be changed to allow for reader priority or writer priority. See 05_interaction slides 58,59

20
Q

What are semaphores? What is their implementation?

A

Semaphores are lock objects that allow to secure critical sections.

A semaphore is a capacity lock S, with operations P(S), V(S) instead of Lock(S) and Unlock(S).

P and V are atomic operations. P decrements a counter, V increments the counter.

They can be used to solve simple resource management problems.

When the capacity is set for 1, it allows for mutual exclusion.