lean4-htt/src/runtime
Marcelo Lynch 5d41b3bdce
fix: avoid deadlock by not throttling workers when the task manager is shutting down (#12052)
This PR avoids a potential deadlock on shutdown of a Lean program when
the number of pooled threads has temporarily been pushed above the
limit.

There's a potential race between the finalizer "waking up everyone"
after setting `m_shutting_down = true` and a worker that is about to be
throttled because of concurrency limits.

- `m_max_std_workers = 1`, `m_std_workers.size() = 2`, and the queue
still has tasks.
- Finalizer sets `m_shutting_down = true` and calls `notify_all()` while
a worker is running a task (outside of the mutex).
- Worker finishes a task, re-enters the loop, sees work, and "should
wait" because `active >= max`.
- Worker then calls `wait()` after the notify and never wakes, so
`join()` in the finalizer hangs.

This PR avoids the worker being blocked by not `wait()`ing if we are
already shutting down. The code is restructured a bit for readability,
where the first section is "there's no work in the queue" and the next
section is "there is some work in the queue"
2026-02-02 16:14:32 +00:00
..
uv fix: Signal.Handler segmentation fault with Selector (#11724) 2025-12-27 02:07:00 +00:00
alloc.cpp
alloc.h
allocprof.cpp
allocprof.h
apply.cpp fix: deallocation for closures in non default configurations (#11217) 2025-11-17 16:27:20 +00:00
apply.h
array_ref.h perf: mark move constructors and assignment operators as noexcept (#10784) 2025-10-22 14:21:51 +00:00
buffer.h
byteslice.cpp feat: add useful functions in Parsec, add error variant and Std.Data.ByteSlice (#9599) 2025-09-11 14:53:41 +00:00
byteslice.h feat: add useful functions in Parsec, add error variant and Std.Data.ByteSlice (#9599) 2025-09-11 14:53:41 +00:00
CMakeLists.txt chore: reformat all cmake files (#12218) 2026-01-28 18:23:08 +00:00
compact.cpp fix: ensure padding bytes for lean::mpz objects in olean files are zero (#11485) 2025-12-09 10:59:15 +00:00
compact.h fix: ensure padding bytes for lean::mpz objects in olean files are zero (#11485) 2025-12-09 10:59:15 +00:00
debug.cpp refactor: port shell option processing to Lean (v2) (#11434) 2025-12-02 17:41:51 +00:00
debug.h
exception.cpp doc: add link to reference manual in stack overflow message (#12157) 2026-01-26 07:56:48 +00:00
exception.h
flet.h
hash.cpp
hash.h
init_module.cpp
init_module.h
int.h
interrupt.cpp feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
interrupt.h
io.cpp chore: fix typo (#11883) 2026-01-03 11:36:50 +00:00
io.h fix: handle NUL bytes in IO functions (#9616) 2025-08-01 06:12:53 +00:00
libuv.cpp feat: add signal handling support using libuv (#9258) 2025-09-15 13:09:50 +00:00
libuv.h feat: add signal handling support using libuv (#9258) 2025-09-15 13:09:50 +00:00
list_ref.h perf: mark move constructors and assignment operators as noexcept (#10784) 2025-10-22 14:21:51 +00:00
memory.cpp feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
memory.h
mpn.cpp
mpn.h
mpz.cpp fix: call delete [] on array allocations (#11453) 2025-12-10 16:51:54 +00:00
mpz.h
mutex.cpp feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
mutex.h
object.cpp fix: avoid deadlock by not throttling workers when the task manager is shutting down (#12052) 2026-02-02 16:14:32 +00:00
object.h fix: revert the waitAny refactoring (#11000) 2025-10-29 08:27:16 +00:00
object_ref.cpp
object_ref.h perf: mark move constructors and assignment operators as noexcept (#10784) 2025-10-22 14:21:51 +00:00
option_ref.h perf: mark move constructors and assignment operators as noexcept (#10784) 2025-10-22 14:21:51 +00:00
optional.h perf: mark move constructors and assignment operators as noexcept (#10784) 2025-10-22 14:21:51 +00:00
pair_ref.h perf: mark move constructors and assignment operators as noexcept (#10784) 2025-10-22 14:21:51 +00:00
platform.cpp feat: ignore lean -R if module name is in setup (#8874) 2025-06-23 17:55:52 +00:00
platform.h chore: reduce src/include/lean 2021-09-07 08:24:54 -07:00
process.cpp fix: IO.Process.spawn empty env var on Windows (#12220) 2026-01-31 19:17:26 +00:00
process.h
sharecommon.cpp
sharecommon.h
sstream.h
stack_overflow.cpp
stack_overflow.h
stackinfo.cpp
stackinfo.h
string_ref.h perf: mark move constructors and assignment operators as noexcept (#10784) 2025-10-22 14:21:51 +00:00
thread.cpp refactor: port shell option processing to Lean (v2) (#11434) 2025-12-02 17:41:51 +00:00
thread.h perf: mark move constructors and assignment operators as noexcept (#10784) 2025-10-22 14:21:51 +00:00
utf8.cpp
utf8.h