Conversation
… corrupted while enqueuing from multiple threads
There was a problem hiding this comment.
Pull Request Overview
This PR introduces thread-safe context operations by adding a WithLock() method to prevent race conditions in texture loading and freeing operations. The change addresses concurrent access issues that could corrupt texture queues when multiple goroutines perform texture operations simultaneously.
- Added
Context.WithLock()method for mutex-protected operations - Protected texture queue enqueue operations with proper locking
- Wrapped texture queue processing in the render loop with mutex protection
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Context.go | Adds WithLock() method for thread-safe context operations |
| Texture.go | Wraps texture loading and freeing queue operations with mutex protection |
| MasterWindow.go | Protects texture queue processing during render with WithLock() |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| func (c *GIUContext) WithLock(fn func()) { | ||
| c.m.Lock() | ||
| defer c.m.Unlock() | ||
| fn() | ||
| } |
There was a problem hiding this comment.
The WithLock method lacks documentation. Add a comment explaining its purpose for thread-safe execution of functions while holding the context mutex.
gucio321
left a comment
There was a problem hiding this comment.
@dizzyd Thank you for this PR (and sorry for late review).
Generally, it ok (I like the idea).
The only problem is the linter that you need to fix (just add whatever copilot wrote in its comment as a doc comment on your WithLock function)
Summary
The texture loading and freeing queues were not thread-safe when accessed from multiple goroutines. This could lead to queue corruption and unpredictable behavior when textures were being loaded or freed concurrently.
Thus, I added a WithLock() method to the GIUContext that safely executes functions while holding the context mutex. This ensures that:
Files modified: