Short answer
Multithreading means several threads of execution share one process and, in the usual model, its memory. Python's threading module can run those threads, but the default CPython build lets only one thread execute Python bytecode at a time. C++ std::thread, since C++11, runs functions concurrently and can do CPU work in parallel when the system allows it. A web worker is a different mechanism, with another global scope.
Last verified against the sources listed below.
Key takeaways
- A thread is a smaller unit of a process. Python threads share that process's memory.
- The Python 3.15.2 docs say the default GIL runs one bytecode thread at a time.
- Those docs point CPU-bound Python work at processes, not at the default threads.
- std::thread starts on construction, join waits, and detach lets the thread continue alone.
- Web workers use a background thread and postMessage. They are not Python threads.
What is multithreading? It is the use of more than one thread inside a single process, so several sequences of instructions can be in progress together. Whether those threads actually run Python or C++ instructions at the same moment depends on the runtime, not on the word alone.
The pages below are the Python 3.15.2 library docs, the matching glossary, PEP 703, cppreference for std::thread, and MDN for web workers. A browser worker is called out as a different mechanism.
What is multithreading in programming?
In programming, multithreading means a process holds multiple threads, which are smaller units that can run at the same time and often share that process’s memory.
The threading module states that shape directly. It builds higher-level thread tools on the lower-level _thread module.
It is not available on WASI, and it does not work on WebAssembly. Since Python 3.7 the module has always been available where the platform allows it.
Sharing memory is why threads can hand each other data without a copy, and why they can also step on the same object. The Python glossary says a high-level statement such as x += 1 is not atomic, because it is several bytecode operations. Locks exist so one thread can keep another out of a critical stretch.
How multithreading works
One process owns the memory, and the operating system schedules the threads. Only some of those threads may hold the right to run language code at a given instant.
In the default CPython story, a thread must hold the global interpreter lock before it runs Python bytecode. The glossary says the lock assures that only one thread executes Python bytecode at a time. That makes objects such as dict safer to share, and it gives up much of the parallelism of a multi-processor machine.
The lock is released during I/O. Some extension modules also release it for heavy work such as compression or hashing.
The parallelism entry on the same page says that, on GIL builds, using several CPU cores typically means multiple processes, such as multiprocessing, or native extensions that release the lock. Free-threaded Python can run Python code on different cores at once. That is a different build, described in the next section.
Node’s about page describes a different default. It is an event-driven runtime that does not start a thread per connection. Extra cores, on that page, come from child processes and the cluster module.
How multithreading works in Python
You create threading.Thread objects, start them, and join them. On the default build they overlap waiting, not CPU-bound Python bytecode.
The threading introduction says threads help when work is I/O bound, such as files or network calls, because much of the time is spent waiting. Its example starts one thread per link, sleeps to imitate a request, then joins every thread. The CPython note on that page says only one thread executes Python code at once, and it points CPU-heavy programs at multiprocessing or concurrent.futures.ProcessPoolExecutor.
The same page says the GIL limits gains on CPU-bound tasks because only one thread runs Python bytecode at a time. As of Python 3.13, free-threaded builds can disable the GIL. The page says that feature is not available by default and cites PEP 703.
PEP 703 is Final, lists Python-Version 3.13, and was created on 09-Jan-2023. Its abstract says the GIL prevents multiple threads from executing Python code at the same time, and it proposes a --disable-gil build.
The page now calls itself a historical document and sends readers to the current free-threading docs. Do not read the proposal as the default interpreter you get from python.org.
What is multithreading in C++?
It is the std::thread class, in the header <thread> since C++11, representing one thread of execution so several functions can run concurrently.
cppreference says execution begins as soon as the thread object is constructed, aside from scheduling delay, at the function you pass in. The function’s return value is ignored.
An exception that escapes that function calls std::terminate. Results go back through std::promise or through shared variables, which may need synchronization such as std::mutex and std::atomic.
join waits until the thread finishes. detach lets it run on without the handle. The destructor requires the thread to be joined or detached already.
Two std::thread objects cannot represent the same thread. The type can be moved and cannot be copied. hardware_concurrency returns how many concurrent threads the implementation claims to support.
The same page documents name_hint and stack_size_hint since C++29. Those hints suggest a name and a stack size. They do not by themselves prove a particular core count.
How do web workers differ?
Web workers run scripts on a background thread in a separate global scope. They are not threads inside your Python process, and they do not share the page’s DOM.
MDN’s worker guide says a worker is constructed with Worker and a script URL. Using window inside the worker fails, because the scope is not the page. You cannot directly change the DOM from the worker.
Messages use postMessage, and the data is copied rather than shared. Workers may open further workers on the same origin, and they may call fetch.
| Mechanism | Shares the caller’s memory? | CPU work in parallel? |
|---|---|---|
| Python threads, default GIL | Yes, one process | One bytecode thread at a time. I/O can overlap. |
| Free-threaded CPython | Yes | The docs say Python code can run on different cores. Not the default build. |
std::thread |
Shared variables need synchronization | The class is defined so functions execute concurrently. |
| Web worker | No. postMessage copies data. | A background thread, separate from the page, with no direct DOM access. |
A worker guide on this site spells out the browser side in more detail.
Programming paradigms is the wider map of ways to structure a program. Threads are one execution model, not a syntax style.
Service workers and web workers covers the browser mechanisms. A service worker is not the Python GIL, and a web worker is not std::thread.
The SVG to JSX converter emits JavaScript that runs on the page’s thread. Nothing in that output starts a worker. Add a Worker yourself if the script should leave the main thread.
Frequently asked questions
Do Python threads speed up CPU-bound work?
Not on the default build described in the threading docs. That page says only one thread can execute Python code at once because of the global interpreter lock, and that the lock limits the gains for CPU-bound tasks. It tells you to use multiprocessing or ProcessPoolExecutor when you want more of a multi-core machine. Threads stay appropriate for I/O-bound work, because the lock is released around blocking I/O.
What changed for the GIL in Python 3.13?
The glossary and the threading page both say that, as of Python 3.13, a build can disable the GIL. The threading page says free-threaded builds are not available by default and points at PEP 703. PEP 703 is marked Final, names Python 3.13, and its abstract says the lock prevents multiple threads from executing Python code at the same time.
What does std::thread do when the function throws?
cppreference says the return value of the top-level function is ignored. If that function exits by throwing an exception, std::terminate is called. To pass a result or an exception back, the page points at std::promise or at shared variables, and shared variables may need std::mutex or std::atomic. The thread begins as soon as the std::thread object is constructed, aside from scheduling delay. The class has no separate start call.
Are web workers the same as sharing memory in one process?
No. MDN says a worker runs in another global context, not the page's window, and that you cannot directly change the DOM from the worker. Data sent with postMessage is copied rather than shared. A dedicated worker is reachable from the script that created it. Shared workers can be reached from more than one script. That is a different mechanism from Python threads, which the threading page says share one memory space inside one process.
Does Node.js use one thread for every connection?
The Node about page argues against that model. It says thread-based networking is inefficient and hard to use, and that Node uses an event loop instead, so the process does not block except on synchronous standard-library I/O. The same page says you can still use more cores by spawning child processes with child_process.fork or the cluster module. MDN's execution model separately notes worker threads in Node.
Sources
- threading · Python Software Foundation, 2026
- Python glossary · Python Software Foundation, 2026
- PEP 703 · Python Enhancement Proposals, 2026
- std::thread · cppreference, 2026
- Using web workers · MDN, 2026
- About Node.js · Node.js, 2026