Concurrency II Flashcards

1
Q

What does join() do

A

Allows one thread to wait for the completion of another

Can respond to an interrupt

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

What does yield() do?

A

Pauses currently executing thread and allows other threads of other priorities to execute

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

Name the 5 states in the lifecycle of a thread

A

New => Initializing the thread

Runnable => start() must be called to get to this state, runnable is when the thread is ready to be run by waiting for CPU time to run

Running => Currently being processed by CPU. Changing from runnable to running state is OS dependent, since this is what schedules thread timeslices.

Dead => thread execution complete

Waiting/ Sleeping/ Blocking => when the thread in running state. One of the methods stated are called, must wait to be notified/ sleep time to be finished before going back to runnable state.

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

Give 3 differences between wait and sleep

A

Wait: must be in a block that is synchronized to the monitor object
Sleep: doesn’t need to occur in a synchronized block

Wait: releases the lock when called (doesn’t sacrifice remainder timeslice)
Sleep: Retains the lock and sacrifices the remainder of its timeslice

Wait: Wakes up when notified
Sleep: Woken up by an interruption

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

What do the methods wait() and notify() do

A

Objects are monitored using a lock; wait() releases the lock, notify() hands the lock to the waiting thread once the block that notified the thread completes execution

wait() => waits for a condition to occur, must call from synchronized methods

notify() => notifies a waiting thread that a condition has occurred

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

What is livelock

A

When two threads are too busy responding to each other to do work

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

1) What is starvation

When does it occur most often

A

1) When a thread can’t gain access to shared resources because another thread is frequently calling the objects’ method.
2) When a thread is synchronized with methods that has faster execution times

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

What is a deadlock

A

Occurs when two or more processes are waiting for each other to release a resource

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

Give 3 differences between wait and sleep

A

Wait: must be in a block that is synchronized to the monitor object
Sleep: doesn’t need to occur in a synchronized block

Wait: releases the lock when called (doesn’t sacrifice remainder timeslice)
Sleep: Retains the lock and sacrifices the remainder of its timeslice

Wait: Wakes up when notified
Sleep: Woken up by an interruption

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