Consider making egui::Context !Send+!Sync
- Dominant language
- Rust
- Stars
- 30.6k
- Forks
- 2.1k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 72
Description
Prompted by https://github.com/emilk/egui/pull/1398
Currently `Context` and `Shape` are both `Send+Sync`. This means `Shape::Callback` can only capture things that are `Send+Sync`, even though almost all users will be running their UI code on the the paint thread.
We could consider making `Shape: !Send + !Sync`, but that would mean `egui::Context` could not be `Send+Sync` either (because the egui context stores shapes). This could actually be fine. `egui::Context` should only be used from a background thread for calling `request_repaint` and allocating textures. These could be made separate parts of the egui Context, so that one would do:
``` rust
let repaint_signal = egui_ctx.repaint_signal();
let tex_mngr = egui_ctx.tex_mngr();
std::thread::spawn(move || {
// We can use repaint_signal and tex_mngr here,
// but NOT `egui_ctx`.
}):
```
Making `Context: !Sync` would also solve deadlocks discussed in #1379 and #1380.
The downside of this is that it would stop users from running their UI code in a separate thread from their main window/paint thread.
Related:
* https://github.com/emilk/egui/issues/1379
* https://github.com/emilk/egui/pull/1380
* https://github.com/emilk/egui/pull/1389
Contributor guide
Research direction
Start by reading the linked PR #1398 and the related issues #1379 and #1380, plus PRs #1380 and #1389, to understand the existing threading constraints and proposed direction. The issue does not identify files, tests, or a settled implementation, and completion would require agreement on the Context, repaint signal, and texture manager API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100