Skip to content

Conversation

luigifcruz
Copy link
Contributor

This pull request proposes to add a @synchronized mutex to control access to self.bufferCache on the Metal implementation file. This avoids a situation where this NSArray is mutated by the dispatch_async(...) while being enumerated by dequeueReusableBufferOfLength(...). This scenario happens when the ImGui render loop is offloaded to a different thread after being initialized on a parent thread. As far as I understand, this change won't add overhead while running on a single thread but will avoid eventual crashes if the circumstance described above happens.

@ocornut ocornut changed the title add dispatch synchronization Metal: add dispatch synchronization Jul 4, 2022
@ocornut
Copy link
Owner

ocornut commented Jul 4, 2022

Tagging @warrenm for feedback as this is all a mystery to me :)

@warrenm
Copy link
Contributor

warrenm commented Jul 4, 2022

Looks like an improvement to me. We could also use os_unfair_lock here, but this PR should mitigate the issue described and is idiomatic and performant.

@ocornut
Copy link
Owner

ocornut commented Jul 5, 2022

Merged! Thank you Luigi for the PR and Warren for the review!

@ocornut ocornut closed this Jul 5, 2022
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.

3 participants