Closed majis15 closed 1 year ago
这是来自QQ邮箱的自动回复邮件。 邮件已收到
It's an NSRecursiveLock, there basically to prevent multiple threads from triggering multiple resolutions and/or write errors when the wrapper is accessed for the first time.
And it's recursive since making A could make a B which makes a C and so on. See the docs on a resolution cycle.
It's an NSRecursiveLock, there basically to prevent multiple threads from triggering multiple resolutions and/or write errors when the wrapper is accessed for the first time.
And it's recursive since making A could make a B which makes a C and so on. See the docs on a resolution cycle.
Thank you for the answer.
I checked the docs and there is everything fine. My question concerns the logic inside mutating get {...
of the LazyInjected
.
Resolver.resolve
method used there is already thread safe so as I understand now we have to take care of initialize
property. To do it we can use just an NSLock
, can't we? Or maybe I miss something? What is the point of using the same instance of ResolverRecursiveLock
here?
You can't just lock initialize, you have to lock the changes from resolving the dependency as well. Adding a separate lock increases the footprint of each wrapper and also increases the chances of deadlocking. It's better and faster to use the same recursive lock which will be called anyway.
Ok, I got it. Thank you very much.
I like this library and its compactness so its source code is easy for reading. Now I have a question and hope to get the answer from you.
In
LazyInjected
property wrapper the samelock
is used as in classResolver
. However I couldn't manage why. Is there any advantage of using the same instance or we can just use a new instance ofNSLock
for example.