Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix BSSingleton.source access with multi-thread #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RetVal
Copy link

@RetVal RetVal commented Jul 15, 2016

dispatch_apply(1000, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(size_t idx) {
[inject getInstance:[TestClass class]]; // which bind to BSSingleton scope, because BSSingleton's source is nonatomic, will crash inside [scope scope:provider], the BSSingleton BSScope protocol implement.
});

@baek-jinoo
Copy link

We are seeing a bug where multiple background thread activities are causing a crash with the stack trace as seen below. Can we get someone to talk about this fix for the ones that involve the [BSSinglton scope:] call? With regards to inFlightKeys I am wondering if it's related to the Thread specific dictionary. Let me know what you think.

screen shot 2016-10-21 at 12 20 19 pm

screen shot 2016-10-21 at 12 21 27 pm

screen shot 2016-10-21 at 12 22 07 pm

screen shot 2016-10-21 at 12 23 17 pm

@RetVal
Copy link
Author

RetVal commented Jan 6, 2017

the BSSingleton scope, because BSSingleton's source is nonatomic, [scope scope:provider] will try to use the source of BSSingleton, step is

  1. retain it
  2. use it
  3. set the source to nil
  4. release it

But in the multi-thread environment, [singleton scope:] will set the singleton's source property, [singleton provide:injector:] will reset the source to nil if instance is nil, and the source property is not marked as atomic, so getter and setter will case the multi-thread problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants