Concurrency Flashcards

1
Q

What is concurrency

A

Perform multiple processes at same time including the potential interaction between them

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

What are threads

A

Lightweight processes

exist within a process

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

Multithreading vs multitasking

A

Multithreading- shared memory space (each thread has its own local variables in the local memory.

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

What is non determinism?

A

We dont know when the OS will schedule threads.

Outputs can vary.

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

What is liveness?

A

We need to know that code performs correctly in time.

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

What is race conditions?

A

When two threads try to access/change data at the same time it’s known as a race condition
Fix with synchronisation

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

Atomic actions are…

A

self contained, they either happen or they don’t. cant be stopped in middle.
Read and writes are atomic for all variables declared volatile.

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

What is deadlock?

A

Two or more threads are blocked forever, waiting for each other. Deadlock occurs when multiple threads need the same locks but obtain them in different order.

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

What is starvation?

A

Where a thread can’t gain regular access to shared resources because another thread is frequently calling the object’s methods.

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

What is livelock?

A

A little like deadlock except that it occurs when two threads are too busy responding to one another to do work

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

wait()

A

Waits for a condition to occur, must call from synchronised method/block (releases the lock)

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

notify()

A

Notifies a thread in wait() that the condition has occured, must call from synchronised method/block.

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

sleep()

A

Does not need to occur in a synchronised block
Retains the monitor (lock) when called and sacrifices the remainder of its timeslice
A sleeping thread can only be woken up by an interruption (not by notify)

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

5 states of thread

A
New
Runnable
Running
Waiting/Sleeping/Blocking
Dead
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

yield()

A

yield() causes the currently executing thread object to pause and allow other threads to execute.
If no other threads of the same priority need to execute, execution of this thread continues
Identifies the current thread as doing something not particularly important

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

join()

A

Simple function allows one thread to wait for the completion of another.