4 - Threads Flashcards

1
Q

Define Threading:

A

Multiple threads of execution within a single process.

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

Is forking a process efficient? If not, why?

A

No, because it copies everything.

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

Define a Thread:

A

A tread is a basic unit of CPU utilization.

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

Do Threads of a process have their own separate memory or share memory together?

A

Threads of a process share memory but can execute independently.

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

In Web Servers, why is Forking inefficient compared to threading other than because it copies everything?

A

Web serveres have caches for read pages - forking means that these caches cannot be shared. Threads allow for these caches to be shared.

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

What do threads share?

A
  • Process Address space (text, data, heap)

- OS State (open files, sockets, locks)

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

What do threads not share?

A

They have their own CPU context:

- Program counter, Stack pointer, register state, stacks

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

Give 4 benefits of threads:

A

Responsiveness
Resource Sharing
Allocating memory and resources for process creation is costly which is avoided.
Context-switching is faster

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

What does a thread library provide for the programmer?

A

An API for creating and managing threads

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

What are the 3 main libraries?

A

1) POSIX Pthreads
2) Win32
3) Java

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

True or false: Threads also share global variables which is a another pros.

A

False; sharing global variables is dangerous

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