Mod 1: Thread properties Flashcards

1
Q

What is a thread?

A

(1) A single sequential flow of control within a program
(2) Sequence of instruction
(3) A unit of work that can be executed

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

What does a thread share with the process and what does it has its own of?

A

It do share

(1) same memory space
(2) same program code and global data

but has its own

(1) set of registers
(2) stack

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

Why is using single-threaded applications on modern computers underuse the capacity of of the computer?

A

Because modern computer often have multiple cores serving as mini-CPU. Using a single-threaded application loads one core with a lot of work, while the other cores stay idle.

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

What are the four typical states that a thread can have?

A

(1) Ready
(2) Running/Active
(3) Blocked/Waiting
(4) Terminated

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

What does a “ready” thread mean?

A

Created, but not started

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

What can cause a thread to die?

A
  • It is done with its task
  • Exception or other unusual event
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When does thread blocking occur?

A

When a thread is unable to continue its execution because it is waiting for something

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

Give example for what thread could be “waiting” on

A

(1) Resources to become available
(2) Conditions to be true
(3) Event to occur

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

What happens when a thread is blocked?

A

It becomes temporarily suspended and other threads are allowed to execute

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

How can a blocked thread resume its work?

A

By receiving CPU-time again

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

What is “sleep”?

A

Timed waiting

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

Why would we want to put a thread in sleep-mode?

A

to make processor time available for other threads

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

What happens if there is no CPU time when the sleep time is over?

A

Nothing, the thread in sleeping-state need to receive CPU-time before resuming its task

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

What is the difference between a foreground thread and a background thread?

A

a foreground thread keep the application alive and the background thread is running “behind the scenes”, this mean that if the foreground thread is terminated and we exit the application, the background thread will die regardless of if they are done with their tasks

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

What is a foreground thread?

A

The thread keeping the application alive, JVM cannot exit the application when there is a foreground thread running

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

Explain why multithreaded programs are non-deterministic

A

Becauses every thread has its own path of execution and we cannot controll the flow of execution. The output can be different every time we run, despite the same input.

17
Q

Will a thread automatically start upon creation?

A

No, the thread has to be started after being created

18
Q

What is a “join”-method?

A

Join is a synchronization method that blocks the calling thread (that is, the thread that calls the method) until the thread whose Join method is called has completed

19
Q

Why is “join”-method used?

A

Join is used when we want one thread to wait for the completion of another thread

20
Q

How does the “join”-method work if we want one thread to wait for completion of another thread?

A

The join method of a thread is used to let the caller method wait until the threads whose join method is called is terminated.

21
Q

When is the first and only mandatory thread creating?

A

at run-time, its job is to keep the application running