Skip to content

fix(Foundation): Thread::tryJoin returns true after the thread was joined #5016 - #5595

Merged
aleks-f merged 2 commits into
pocoproject:mainfrom
555aaditya:5016-thread-tryjoin-after-join
Oct 26, 2026
Merged

aleks-f merged 2 commits into
pocoproject:mainfrom
555aaditya:5016-thread-tryjoin-after-join

Conversation

@555aaditya

Copy link
Copy Markdown
Contributor

Closes #5016.

On POSIX, Thread::tryJoin() returns false once the thread has been joined, either by an earlier tryJoin() or by join(). ThreadData::started stays true after the join, so joinImpl(long) falls through to return false. On Windows, a second call returns true, and the documentation of tryJoin() says it "returns true if the thread has finished".

  • Foundation/src/Thread_POSIX.cpp: joinImpl(long) returns true at once when the thread has already been joined. All other cases are unchanged.

Tests: ThreadTest::testTryJoin calls tryJoin() a second time, and ThreadTest::testJoin calls it after join(). Both assertions fail without the change and pass with it.

Validation on macOS arm64, Apple clang 21, Debug:

  • the full Foundation suite with -ignore cppignore.lnx (1004 tests, OK);
  • ENABLE_COMPILER_WARNINGS=ON, no warnings in the changed file;
  • ThreadTest under ASan, UBSan and TSan;
  • clang-tidy and cppcheck, no findings on the changed lines.

Not run: Linux and Windows.

…ined pocoproject#5016

On POSIX, started stays true after a join, so a second tryJoin()
returned false. Windows and the documented contract return true.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The localized fix addresses the reported behavior with regression coverage for both failure cases and no unresolved findings.

No open issues 🎉

What changed in this PR

Fixes #5016 by making POSIX Thread::tryJoin() return true after a thread has already been joined, matching Windows behavior and the documented contract.

Changes:

  • Returns immediately when the POSIX thread is already joined, preserving other join behavior.
  • Adds regression assertions for repeated tryJoin() calls and tryJoin() after join().
File Description
Foundation/​testsuite/​src/​ThreadTest.cpp Tests both already-joined scenarios.
Foundation/​src/​Thread_POSIX.cpp Returns true for an already-joined thread.

Review effort: Balanced

@555aaditya

Copy link
Copy Markdown
Contributor Author

The macos-clang-cmake-poco-soo-off failure is ProcessRunnerTest::testProcessRunner (line 265, the PID file still exists after stop). This looks like the flake described in #5568; ProcessRunner uses Thread::join(), not tryJoin(). The test passes 10 out of 10 runs locally on macOS with this change.

… writes its PID file pocoproject#5568

ProcessRunnerTest::testProcessRunner failed now and then on a slow
machine with result 258, the test program ended by SIGINT. TestApp
wrote its PID file, which ProcessRunner takes as the program running,
before it blocked SIGINT, SIGQUIT and SIGTERM, so a stop() in between
ended the program with the default action of SIGINT. Sending SIGINT the
moment the PID file appears ended it every time.

MyApp now blocks the termination signals when it is constructed, before
any mode writes a PID file, starts its threads or forks its child, and
waitForTerminationRequest() only waits for them.
@aleks-f
aleks-f merged commit 194b930 into pocoproject:main Oct 26, 2026
52 checks passed
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.

Poco::Thread tryJoin linux/windows different behavior

3 participants