Skip to content

Resolve LAC_THREADS in the CLI, not inside the library#34

Merged
audexdev merged 1 commit into
mainfrom
refactor/cli-owns-thread-env
Jun 4, 2026
Merged

Resolve LAC_THREADS in the CLI, not inside the library#34
audexdev merged 1 commit into
mainfrom
refactor/cli-owns-thread-env

Conversation

@audexdev

@audexdev audexdev commented Jun 4, 2026

Copy link
Copy Markdown
Owner

What

Phase 1 of docs/refactor-roadmap.md (#27): stop the library from reading the environment.

The encoder and decoder previously called resolve_thread_limit() inside encode() / decode(), which read getenv("LAC_THREADS"). A library call should not depend on ambient process state, and that read is not safe against a concurrent setenv.

Changes

  • Remove resolve_thread_limit() from thread_limit.hpp (keep the pure parse_thread_limit() string parser).
  • Block/LAC encoder and decoder now use their explicit thread_count directly (0 = auto) and no longer include thread_limit.hpp.
  • main.cpp resolves the thread count once via resolve_cli_thread_count(): --threads wins, otherwise LAC_THREADS, and passes an explicit value to the library (encode + both decode paths).
  • README: clarify that LAC_THREADS applies to the lac_cli binary (and CLI subprocess tests); internal codec unit tests set their own thread counts.

Behavior

  • Via the CLI: unchanged--threads=N still overrides LAC_THREADS, both still cap workers.
  • Direct library use: no longer reads the environment. Callers pass set_thread_count() (0 = auto). This is the intended point of the change. docs/supported-formats.md already documents --threads / LAC_THREADS as CLI options, which remains accurate.

Deferred

Verification (local, macOS)

  • Clean configure + build succeeds; resolve_thread_limit is gone and src/codec/ contains no getenv.
  • ctest: 2/2 suites pass, including the explicit thread-count assertions in run_thread_limit_tests / run_decoder_thread_tests (which use set_thread_count, not the environment).
  • lac_cli selftest: passes.

Refs #27

The encoder and decoder previously called resolve_thread_limit() deep inside
encode()/decode(), which read getenv("LAC_THREADS"). That made a library call
depend on ambient process state and was not safe against concurrent setenv.

Move environment resolution to the CLI: main.cpp now resolves --threads (which
takes precedence) and otherwise LAC_THREADS via resolve_cli_thread_count(), and
passes an explicit thread count to the library. The encoder/decoder use that
count directly (0 = auto) and no longer include thread_limit.hpp.

CLI behavior is unchanged. Direct library use no longer reads the environment;
README is updated to state that LAC_THREADS applies to lac_cli (the unit tests
set their own thread counts via set_thread_count).

Refs #27

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@audexdev audexdev merged commit b4eeabb into main Jun 4, 2026
8 checks passed
@audexdev audexdev deleted the refactor/cli-owns-thread-env branch June 4, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant