Threads Flashcards

1
Q

Imagine RAM containing one piece of code and two programs sharing that piece of code. How will the CPU see this?

A

Each of the two programs has a PCB, so for the CPU, there are two different programs executing.

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

Imagine RAM containing one piece of code and two programs sharing that piece of code. How will the RAM see this?

A

There is only one piece of code in memory so there is only one program.

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

What is a thread?

A

In computer science, a thread of execution is the smallest sequence of programmed instructions that can be managed independently by a scheduler, which is typically a part of the operating system.

-Wikipedia

So a thread is something like: RAM containing one piece of code and two programs sharing that piece of code.

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

Imagine RAM containing one piece of code and two programs sharing that piece of code.

What does this mean?

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

Agnostic

A

Part of the code that is compatible with two different programs.

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

What parts of this code is agnostic?

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

Let P1 and P2 share the following code. What happens when P1’s quanta finishes and P2 enters?

A

All the information saved in the registers for P1 has to be stored in the PCB since P2 will use those same registers but with different values.

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

*What is overhead?

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

Multi-Tasking

A

Each process has only ONE execution.

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

Multi-Threading

A

Each process has multiple processes running.

ex: In a browser, you can have multiple tabs.

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

Spooling

A

Spooling allows programs to ”hand-off” work to be done by the peripheral and then proceed to other tasks, or to not begin until input has been transcribed.

-Wikipedia

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

Is this multi-tasking or multi-threading, why?

A

Multi-tasking, since each process has its own spooler.

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

Is this spooler a multi-tasking version or multi-threading version, why?

A

Multi-threading since the processes are sharing a spooler.

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

In the multi-threading version of a spooler, what could we use to manage who enters the spooler first?

A

A queue

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

True or false,

In the multi-thread version of the spooler quanta still applies

A

True

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

What does DLL mean?

A

Dynamic Link Library.

Shared code. This is a library that is not appended to your code but rather gets pointed by your code in order to execute it.

17
Q

In threading, we don’t want threads to share the stack space why?

A

Since there is many processes using the same space in the stack, it would be hard to keep track of who is poping and pushing.

18
Q

What happens to the stack when we have threads?

A

One way of doing this is by giving the stack to each child in their PCB. That way they can each take care of their variables.

Notice, the heap will stay in RAM, this is because it is not a stack and when we malloc we get a block of memory.

19
Q

Lightweight Process (LWP)

A

It’s called lightweight since it does not take a lot of energy to the computer to do it.

This is usually done by taking a PCB in RAM and make a close of it in RAM. This is fast and easy to do.

20
Q

Say one main difference between a normal process and a LWP.

A

The run-time stack is inside the PCB. A regular PCB does not have a run-time stack section.

21
Q

Imagine a program opens a file and then creates a child.

What happens with the opened file?

A

The child will also be pointing to that same file. But if the child, later on, opens other files, this would be different from the parent.

22
Q

Threads as data structures.

Why do we like to use linked lists to represent threads?

A

Linked lists are infinite and we can connect each cell to many cells. So we can easily have a 2D linked list.

23
Q

Why is it good to limit the number of fopen() in a script?

A

fopen() will take up RAM. If you have a program that uses fopen() a lot, then it will stop the other programs from having RAM.

24
Q

Mention 4 benefits of threads

A
  • Responsive (if a program gets stuck, the other programs keep running)
  • Resource sharing
  • Economy (cloning)
  • Multiprocessor architecture advantages
25
Q

What would the complete memory look like with processes and OS PCB/Thread management?

A
26
Q

What happens to a2’s quanta?

A

It has to share it amongst the children.

27
Q

Name two ways of thinking about threading.

A

OS

Software

28
Q

What is software threading?

A

It is like a simulation of what happened in the OS when there are threads.

29
Q

What are some advantages and disadvantages of the first model?

A

Advantages:

  • The LWP has its own quanta

Disadvantages:

  • It could get crazy if you open many of them
  • If the LWP freezes it freezes everything
30
Q
A
31
Q
A