Skip to content

Conversation

tboogh
Copy link
Contributor

@tboogh tboogh commented Oct 4, 2025

This is a proposal to make the access to the Mock thread safe so that it can be used in tests read/write mocks concurrently. The NSLock ensures that access to the calls dictionary is safe. We have used a similar approach where we used a dispatch_semaphore but NSLock feels like it's a cleaner approach. This should solve the problems discussed in issue #20.

The test written is a quick an dirty way to replicate the issue in a minimal way.

@tboogh tboogh force-pushed the thread-safe-access branch from 824b2be to 2454dd8 Compare October 4, 2025 15:36
@danielsaidi
Copy link
Owner

Hi @tboogh

Thank you, it sounds great! I will take a look once I'm back from conference travels!

I discussed the approach with people at the conference, and one suggested looking into OSUnfairLock for performance.

Not that I think it matters for tests, but maybe food for thought?

https://developer.apple.com/documentation/os/osallocatedunfairlock

@danielsaidi danielsaidi added the tech Internal tech fixes, refactorings etc. label Oct 9, 2025
@tboogh
Copy link
Contributor Author

tboogh commented Oct 16, 2025

Hi @tboogh

Thank you, it sounds great! I will take a look once I'm back from conference travels!

I discussed the approach with people at the conference, and one suggested looking into OSUnfairLock for performance.

Not that I think it matters for tests, but maybe food for thought?

https://developer.apple.com/documentation/os/osallocatedunfairlock

Interesting, I'll try it out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tech Internal tech fixes, refactorings etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants