Threads Items Flashcards

1
Q

What is a thread of execution (a.k.a. just thread)?

A

A thread of execution, or simply a thread, is the smallest unit of processing that can be performed in an operating system. It represents a single sequence of instructions within a program. A thread is a component of a process and can run concurrently with other threads within the same process.

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

Why might we want to create new threads of execution instead of new processes?

A

Efficiency: Creating and managing threads is typically less resource-intensive and faster than creating and managing processes because threads share the same memory space and resources of the parent process.
Shared State: Threads can easily share data and communicate with each other through the process’s shared memory space without the need for inter-process communication (IPC) mechanisms.
Parallelism: Using multiple threads can improve performance through parallelism, especially on multi-core processors, by allowing different parts of a program to run concurrently.

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

Why might we want to create new processes instead of new threads?

A

Isolation: Processes provide better isolation and fault tolerance because they have separate memory spaces. If one process crashes, it does not affect the others.
Security: Processes are more secure because they do not share memory by default, reducing the risk of unintended data corruption or security vulnerabilities.
Resource Management: Processes can be given distinct resources, permissions, and scheduling priorities, making it easier to manage different tasks with varying requirements.

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

What do threads belonging to the same process share?

A

Memory Space: Threads within the same process share the same address space, including the heap and global variables.
File Descriptors: Threads share file descriptors, meaning they can access the same files and I/O devices.
Code Segment: Threads share the same code segment, so they can execute the same instructions.
Data Segment: Threads share static and global variables.
Other Resources: Threads share other process-wide resources, such as open sockets and environment variables.

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

What don’t threads belonging to the same process share?

A

Thread Stack: Each thread has its own stack for local variables, function calls, and return addresses.
Thread-specific Data: Each thread maintains its own set of registers, including the instruction pointer and stack pointer.
Thread-local Storage: Threads can have their own thread-local storage (TLS) to store data that should be unique to each thread.

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