iphone - Why is my app not crashing when same managed object context is used in different threads? -


i m trying create sample app multi-threading , core data either suppose crash or in deadlock.

i have created concurrent queue , using loop call dispatch_async thrice.

     appdelegate *appdelegate = (appdelegate *)[[uiapplication       sharedapplication] delegate]; nsmanagedobjectcontext *amangedobjectcontext = appdelegate.managedobjectcontext;  (int = 0; i<=2; i++) {           libxmlparser *parser = [[parserclass alloc] init];     parser.delegate = self;     dispatch_async(_queue, ^{         [parser startwithcontext:amangedobjectcontext];      }); } 

//i added concurrent queue see if crashes, had no luck

    (int = 0; i<=2; i++) {     libxmlparser *parser = [[parserclass alloc] init];     parser.delegate = self;     dispatch_async(dispatch_get_main_queue(), ^{         [parser startwithcontext:amangedobjectcontext];      }); } 

i create concurrent queue using technique:

@property (nonatomic) dispatch_queue_t queue; @property (nonatomic) dispatch_queue_t queue;  _queue = dispatch_get_global_queue(dispatch_queue_priority_default, 0); _queue1 = dispatch_get_global_queue(dispatch_queue_priority_default, 0); 

i save data in main context:

 appdelegate *appdelegate = (appdelegate *)[[uiapplication sharedapplication] delegate]; nsmanagedobjectcontext *amangedobjectcontext = appdelegate.managedobjectcontext; nserror *error = nil;  if (![amanagedobjectcontext save:&error]) {     nslog(@"error in adding new bank %@, %@", error, [error userinfo]);     abort(); } 

here m using same main context created in app delegate in different threads. , since breaks containment model in core data, (each thread should have own private context) app should not generate proper output.

the app gets top 100 songs in each dispatch_async. totally 300 songs.

i haven't registered app nsmanagedobjectcontextdidsavenotification either, since have used main context , not multiple. each time save called in different threads on main context self.

i don't understand why app neither in deadlock nor crashing.

can 1 tell me have gone wrong.

i want app either crash or freeze when using same object context in multiple threads when use 1 context in different.

can tell me in case queue access same context simultaneously.should create concurrent queue? tried , did not work.

thank you.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -