Threads Flashcards
What does CPU stand for?
Central Processing Unit
How many cores did CPUs originally have?
1 core
What is significant about the number of cores in a CPU?
The amount of cores matters for how many parallel operations can be performed.
What is meant by parallel operations in a CPU?
Parallel operations refer to multiple processes being executed simultaneously by different cores.
How are threads related to CPU cores?
Each core in a CPU can have multiple threads assigned to it, allowing multiple sequences of programmed instructions to be executed concurrently.
Where can you see how many threads are running on a CPU?
In the Task Manager in Windows.
What does it mean when a thread ‘hangs’?
It stops or waits, often due to a blocking operation or an error.
What is concurrent programming?
Concurrent programming is a programming paradigm where different parts of a program are executed out-of-order or in partial order, without affecting the final outcome.
What happens during core switching between threads?
Core switching between threads, also known as context switching, involves the CPU switching from one thread to another, allowing multiple threads to share the CPU’s resources.
What is asynchronous programming?
Asynchronous programming allows the CPU to switch between threads when one thread is idle or waiting (e.g., during a timeout or sleep), improving efficiency and responsiveness.
What is a thread in the context of programming?
A thread is the smallest unit of processing that can be performed in an operating system, often part of a process.
How does JavaScript handle threading?
JavaScript uses an event-driven, non-blocking I/O model with a single-threaded event loop, utilising Web Workers for parallel execution.
What are Web Workers in JavaScript?
Web Workers are a feature in JavaScript that allow you to run scripts in background threads, enabling parallel execution without interfering with the main execution thread.
What is the main advantage of using asynchronous programming in JavaScript?
The main advantage is that it allows the program to remain responsive by performing other operations while waiting for long-running tasks to complete.
What is a common issue with multi-threading in programming?
A common issue with multi-threading is the potential for race conditions, where multiple threads access shared resources simultaneously, leading to unpredictable results.
What is a deadlock in concurrent programming?
A deadlock is a situation in concurrent programming where two or more threads are unable to proceed because each is waiting for the other to release a resource.
Is Python single-threaded or multi-threaded?
Python is technically capable of multi-threading, but due to the Global Interpreter Lock (GIL), it is often considered effectively single-threaded for CPU-bound tasks. Multi-threading in Python works well for I/O-bound tasks.
Is Java single-threaded or multi-threaded?
Java is multi-threaded. It has built-in support for multi-threading, making it a good choice for concurrent programming.
Is JavaScript single-threaded or multi-threaded?
JavaScript is single-threaded. It runs on a single thread, but it can handle asynchronous operations through its event loop, enabling non-blocking execution.
Is C++ single-threaded or multi-threaded?
C++ is multi-threaded. It provides support for multi-threading through libraries like the C++ Standard Library’s <thread> and various other concurrency features.</thread>
Is Ruby single-threaded or multi-threaded?
Ruby is primarily single-threaded due to the Global Interpreter Lock (GIL), similar to Python. However, JRuby (Ruby on the JVM) can support true multi-threading.
Is Go single-threaded or multi-threaded?
Go (Golang) is multi-threaded. It has built-in support for concurrent programming with goroutines, which are lightweight threads managed by the Go runtime.
Is C# single-threaded or multi-threaded?
C# is multi-threaded. It has extensive support for multi-threading and parallel programming through the .NET framework.
Is Rust single-threaded or multi-threaded?
Rust is multi-threaded. It provides robust support for multi-threading with a strong emphasis on safety and concurrency, avoiding data races through its ownership system.