Skip to content

Fix thread-count runaway in GC/Scenarios/THDChaos test - #131832

Open
VSadov with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-thdchaos-test-failure
Open

Fix thread-count runaway in GC/Scenarios/THDChaos test#131832
VSadov with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-thdchaos-test-failure

Conversation

Copilot AI commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

THDChaos intermittently fails with OutOfMemoryException from Thread.Start — the test creates hundreds of native threads in a burst, which exhausts resources on Arm32's constrained address space.

The bound on successor threads was also ineffective: iCounter is static, but the increment took lock(this), and every LivingObject has a different this. Increments were lost and the iCounter < iThrd check raced, so more threads were spawned than intended.

Changes

  • livingobject.csIncreatCount uses Interlocked.Increment and returns the new value. The successor thread is started only when that increment reserved a slot, making the cap a genuine bound rather than a racy check:

    if( IncreatCount( ) <= ThdChaos.iThrd )
    {
        Thread Mv_Thread = new Thread( new ThreadStart (this.ThreadStart) );
        Mv_Thread.Start( );
    }

    The logging read of iCounter uses Volatile.Read.

  • thdchaos.cs — caps iThrd at 5 on Arm32, consistent with how other thread-heavy tests are throttled there.

Copilot AI self-assigned this Aug 4, 2026
Copilot AI review requested due to automatic review settings August 4, 2026 21:31

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.

Copilot wasn't able to review any files in this pull request.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
16 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Co-authored-by: VSadov <8218165+VSadov@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 4, 2026 21:38
Copilot AI changed the title [WIP] Fix test failure in GC/Scenarios/THDChaos Fix thread-count runaway in GC/Scenarios/THDChaos test Aug 4, 2026
Copilot AI requested a review from VSadov August 4, 2026 21:39

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/tests/GC/Scenarios/THDChaos/livingobject.cs:30

  • The log uses a volatile read for the %100 check but prints iCounter via a separate non-volatile read. Since other threads can increment between the check and the write, this can print non-multiples of 100 (and generally misreport the value that triggered the log). Capture the value once and use it for both the modulo check and the output.
            if( Volatile.Read( ref iCounter )%100 == 0)
            {
                Console.Out.WriteLine( iCounter + " number of threads has been started" );
            }

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @VSadov
See info in area-owners.md if you want to be subscribed.

@VSadov
VSadov requested a review from eduardo-vp August 4, 2026 22:40
@VSadov
VSadov marked this pull request as ready for review August 4, 2026 22:42
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test failure: GC/Scenarios/THDChaos/thdchaos/thdchaos.cmd

3 participants