comparison third_party/libuv/docs/src/threadpool.rst @ 160:948de3f54cea

[ThirdParty] Added libuv
author June Park <parkjune1995@gmail.com>
date Wed, 14 Jan 2026 19:39:52 -0800
parents
children
comparison
equal deleted inserted replaced
159:05cf9467a1c3 160:948de3f54cea
1
2 .. _threadpool:
3
4 Thread pool work scheduling
5 ===========================
6
7 libuv provides a threadpool which can be used to run user code and get notified
8 in the loop thread. This thread pool is internally used to run all file system
9 operations, as well as getaddrinfo and getnameinfo requests.
10
11 Its default size is 4, but it can be changed at startup time by setting the
12 ``UV_THREADPOOL_SIZE`` environment variable to any value (the absolute maximum
13 is 1024).
14
15 .. versionchanged:: 1.30.0 the maximum UV_THREADPOOL_SIZE allowed was increased from 128 to 1024.
16
17 .. versionchanged:: 1.45.0 threads now have an 8 MB stack instead of the
18 (sometimes too low) platform default.
19
20 .. versionchanged:: 1.50.0 threads now have a default name of libuv-worker.
21
22 The threadpool is global and shared across all event loops. When a particular
23 function makes use of the threadpool (e.g. when using :c:func:`uv_queue_work`)
24 libuv preallocates and initializes the maximum number of threads allowed by
25 ``UV_THREADPOOL_SIZE``. More threads usually means more throughput but a higher
26 memory footprint. Thread stacks grow lazily on most platforms though.
27
28 .. note::
29 Note that even though a global thread pool which is shared across all events
30 loops is used, the functions are not thread safe.
31
32
33 Data types
34 ----------
35
36 .. c:type:: uv_work_t
37
38 Work request type.
39
40 .. c:type:: void (*uv_work_cb)(uv_work_t* req)
41
42 Callback passed to :c:func:`uv_queue_work` which will be run on the thread
43 pool.
44
45 .. c:type:: void (*uv_after_work_cb)(uv_work_t* req, int status)
46
47 Callback passed to :c:func:`uv_queue_work` which will be called on the loop
48 thread after the work on the threadpool has been completed. If the work
49 was cancelled using :c:func:`uv_cancel` `status` will be ``UV_ECANCELED``.
50
51
52 Public members
53 ^^^^^^^^^^^^^^
54
55 .. c:member:: uv_loop_t* uv_work_t.loop
56
57 Loop that started this request and where completion will be reported.
58 Readonly.
59
60 .. seealso:: The :c:type:`uv_req_t` members also apply.
61
62
63 API
64 ---
65
66 .. c:function:: int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb, uv_after_work_cb after_work_cb)
67
68 Initializes a work request which will run the given `work_cb` in a thread
69 from the threadpool. Once `work_cb` is completed, `after_work_cb` will be
70 called on the loop thread.
71
72 This request can be cancelled with :c:func:`uv_cancel`.
73
74 .. seealso:: The :c:type:`uv_req_t` API functions also apply.