Skip to content

Fix issues with the threadpool semaphore - #3854

Merged
IntegratedQuantum merged 2 commits into
PixelGuys:masterfrom
IntegratedQuantum:threadpool_issues
Dec 2, 2026
Merged

IntegratedQuantum merged 2 commits into
PixelGuys:masterfrom
IntegratedQuantum:threadpool_issues

Conversation

@IntegratedQuantum

Copy link
Copy Markdown
Member
  • In some places the trueQueueSize could be different than the semaphore state. I fixed the relevant cases and added catch unreachable where the relationship was previously broken.
  • The main issue was related to task reprioritization, which had race conditions.

Consider the following timeline (as possible in the old code):
Thread A is in updateTaskPriority, Thread B is in run, Thread C is in addTask, there is one task currently in the queue.

  • Thread A gets Tasks 1
  • Thread B succeeds on semaphore waiting
  • Thread B tries to get a task, no tasks exist, Thread B ignores this (after this PR this will be unreachable, causing a crash in safe builds)
  • Thread C adds Task 2
  • Thread C posts to the semaphore
  • Thread A succeeds on semaphore waiting
  • Thread A discards Task 1
    Resulting state is that the semaphore is blocked, but there is still one task in the queue.

This is fixed by swapping waiting and getting the task in updateTaskPriority

fixes #3808

@IntegratedQuantum
IntegratedQuantum merged commit 4646167 into PixelGuys:master Dec 2, 2026
4 checks passed
@IntegratedQuantum
IntegratedQuantum deleted the threadpool_issues branch December 2, 2026 19: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.

Chunk generation stops entirely while in high LODs

1 participant