- 1
- 2
- Source: Thread pool
- Daftar diskografi, filmografi, dan bibliografi JKT48
- Washington, D.C.
- Daftar episode Cardcaptor Sakura
- Daftar julukan kota di Amerika Serikat
- Madeline Amy Sweeney
- Thread pool
- Node.js
- Pool
- Task (computing)
- Thread (computing)
- System call
- Green thread
- George Savalas
- Concurrency pattern
- Command pattern
Deadpool 2 (2018)
Deadpool & Wolverine (2024)
Cesium Fallout (2024)
Artikel: Thread pool GudangMovies21 Rebahinxxi
In computer programming, a thread pool is a software design pattern for achieving concurrency of execution in a computer program. Often also called a replicated workers or worker-crew model, a thread pool maintains multiple threads waiting for tasks to be allocated for concurrent execution by the supervising program. By maintaining a pool of threads, the model increases performance and avoids latency in execution due to frequent creation and destruction of threads for short-lived tasks. Another good property - the ability to limit system load, when we use fewer threads than available. The number of available threads is tuned to the computing resources available to the program, such as a parallel task queue after completion of execution.
Performance
The size of a thread pool is the number of threads kept in reserve for executing tasks. It is usually a tunable parameter of the application, adjusted to optimize program performance. Deciding the optimal thread pool size is crucial to optimize performance.
One benefit of a thread pool over creating a new thread for each task is that thread creation and destruction overhead is restricted to the initial creation of the pool, which may result in better performance and better system stability. Creating and destroying a thread and its associated resources can be an expensive process in terms of time. An excessive number of threads in reserve, however, wastes memory, and context-switching between the runnable threads invokes performance penalties. A socket connection to another network host, which might take many CPU cycles to drop and re-establish, can be maintained more efficiently by associating it with a thread that lives over the course of more than one network transaction.
Using a thread pool may be useful even putting aside thread startup time. There are implementations of thread pools that make it trivial to queue up work, control concurrency and sync threads at a higher level than can be done easily when manually managing threads. In these cases the performance benefits of use may be secondary.
Typically, a thread pool executes on a single computer. However, thread pools are conceptually related to server farms in which a master process, which might be a thread pool itself, distributes tasks to worker processes on different computers, in order to increase the overall throughput. Embarrassingly parallel problems are highly amenable to this approach.
The number of threads may be dynamically adjusted during the lifetime of an application based on the number of waiting tasks. For example, a web server can add threads if numerous web page requests come in and can remove threads when those requests taper down. The cost of having a larger thread pool is increased resource usage. The algorithm used to determine when to create or destroy threads affects the overall performance:
Creating too many threads wastes resources and costs time creating the unused threads.
Destroying too many threads requires more time later when creating them again.
Creating threads too slowly might result in poor client performance (long wait times).
Destroying threads too slowly may starve other processes of resources.
In languages
In bash implemented by --max-procs / -P in xargs, for example:
In Go, called worker pool:It will print:
$ time go run worker-pools.go
worker 1 started job 1
worker 2 started job 2
worker 3 started job 3
worker 1 finished job 1
worker 1 started job 4
worker 2 finished job 2
worker 2 started job 5
worker 3 finished job 3
worker 1 finished job 4
worker 2 finished job 5
real 0m2.358s
See also
Asynchrony (computer programming)
Object pool pattern
Concurrency pattern
Grand Central Dispatch
Parallel Extensions
Parallelization
Server farm
Staged event-driven architecture
References
External links
"Query by Slice, Parallel Execute, and Join: A Thread Pool Pattern in Java" by Binildas C. A.
"Thread pools and work queues" by Brian Goetz
"A Method of Worker Thread Pooling" by Pradeep Kumar Sahu
"Work Queue" by Uri Twig: C++ code demonstration of pooled threads executing a work queue.
"Windows Thread Pooling and Execution Chaining"
"Smart Thread Pool" by Ami Bar
"Programming the Thread Pool in the .NET Framework" by David Carmona
"Creating a Notifying Blocking Thread Pool in Java" by Amir Kirsh
"Practical Threaded Programming with Python: Thread Pools and Queues" by Noah Gift
"Optimizing Thread-Pool Strategies for Real-Time CORBA" by Irfan Pyarali, Marina Spivak, Douglas C. Schmidt and Ron Cytron
"Deferred cancellation. A behavioral pattern" by Philipp Bachmann
"A C++17 Thread Pool for High-Performance Scientific Computing" by Barak Shoshany
Kata Kunci Pencarian:
Artikel Terkait "thread pool"
std::thread - cppreference.com
24 Okt 2023 · The class thread represents a single thread of execution. Threads allow multiple functions to execute concurrently. Threads begin execution immediately upon construction of the associated thread object (pending any OS scheduling delays), starting at the top-level function provided as a constructor argument.
std::async - cppreference.com
28 Okt 2024 · The function template std::async runs the function f asynchronously (potentially in a separate thread which might be a part of a thread pool) and returns a std::future that will eventually hold the result of that function call.
Concurrency support library (since C++11) - cppreference.com
28 Jan 2025 · C++ includes built-in support for threads, atomic operations, mutual exclusion, condition variables, and futures.
Multi-threaded executions and data races (since C++11)
15 Jan 2025 · A thread of execution is a flow of control within a program that begins with the invocation of a specific top-level function (by std::thread, std::async, std::jthread (since C++20) or other means), and recursively including every function invocation subsequently executed by …
std::thread::thread - cppreference.com
23 Feb 2024 · Constructs the std::thread object to represent the thread of execution that was represented by other. After this call other no longer represents a thread of execution.
std::thread::hardware_concurrency - cppreference.com
02 Jun 2021 · Returns the number of concurrent threads supported by the implementation. The value should be considered only a hint.
Standard library header <thread> (C++11) - cppreference.com
27 Nov 2023 · stops the execution of the current thread for a specified time duration (function)
Concurrency support library - cppreference.com
14 Agu 2023 · C includes built-in support for threads, atomic operations, mutual exclusion, condition variables, and thread-specific storages. These features are optionally provided: if the macro constant __STDC_NO_THREADS__ is defined by the compiler, the header <threads.h> and all of the names provided in it are not provided;
std::thread::join - cppreference.com
03 Jun 2021 · Blocks the current thread until the thread identified by * this finishes its execution. The completion of the thread identified by * this synchronizes with the corresponding successful return from join() .
std::pmr::synchronized_pool_resource - cppreference.com
18 Des 2023 · synchronized_pool_resource may be accessed from multiple threads without external synchronization, and may have thread-specific pools to reduce synchronization costs. If the memory resource is only accessed from one thread, unsynchronized_pool_resource is …