Skip to content

Thread-local state#2611

Merged
hoffstadt merged 2 commits intohoffstadt:masterfrom
v-ein:feature/thread-local-state
Mar 10, 2026
Merged

Thread-local state#2611
hoffstadt merged 2 commits intohoffstadt:masterfrom
v-ein:feature/thread-local-state

Conversation

@v-ein
Copy link
Copy Markdown
Collaborator

@v-ein v-ein commented Mar 3, 2026


name: Pull Request
about: Create a pull request to help us improve
title: Thread-local state
assignees: ''


Description:
This PR makes internal state thread-local so that multiple threads calling DPG functions do not interfere with each other.

Without this fix, if two threads start creating a massive piece of GUI each (think of loading data into a table in two different windows), they will mess up the container stack and the app will eventually crash trying to add an item to an incompatible parent from another thread.

With this PR, multiple threads can safely use the following functions in parallel:

  • last_item, last_container, last_root
  • push_container_stack, pop_container_stack, top_container_stack, empty_container_stack
  • all the context managers (with item...)
  • capture_next_item
  • generate_uuid (in fact, used on creation of any item).

The last item info, the container stack, and captured item are now thread-local.

Concerning Areas:
None.

@v-ein v-ein requested a review from hoffstadt March 3, 2026 11:08
@hoffstadt hoffstadt merged commit 026ea3b into hoffstadt:master Mar 10, 2026
4 checks passed
@v-ein v-ein deleted the feature/thread-local-state branch March 23, 2026 20:59
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.

2 participants