Lecture 13 Flashcards

1
Q

What is a process?

A

A program that is running

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

What are threads used for?

A

Doing multiple things at the same time, for one program.

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

What memory do threads use?

A

All threads for one program, use the same piece of memory.

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

What is concurrency?

A

Doing multiple tasks at the same time

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

What is parallelism?

A

Splitting one task over multiple processors

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

What are the three ways for your computer to handle multiple threads?

A
  1. Having multiple processors.
  2. Interleaving
  3. Hyperthreading
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In interleaving, how does the order of threads get determined?

A

It is not pre-determined and it depends on a lot of unknown variables. Therefore the order changes per time that you execute, per OS etc.

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

What are Heisenbugs?

A

Bugs that appear because of wrong expectations with regards to the scheduling of threads.

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

What are 2 cons of multi-threading? In what cases is multi-threading useful? give an example

A

It is not necessary and risky.
It is useful for trivially parallelizable problems.
e.g. serving web pages,
processing multiple files with the same algorithm, accepting user input while waiting for something (e.g. a page to load)

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

What are the three important methods that the Java class ‘Thread’ contains?

A

Thread(string name), start(), run()

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

What are the two ways to create a thread in Java?

A
  1. Create a class that inherits from Thread

2. Create a class that implements runnable

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

How do you implement a thread in your MyThread class, if you’re inheriting from Thread?

A

You set the constructor to the Thread constructor (using super) and you redefine the run method, with what your thread should do.

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

How do you activate your thread?

A

You use the start() method (e.g. in your main) to create a thread and to execute run()

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