ios - EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) on dispatch_semaphore_dispose -
i getting exc_bad_instruction (code=exc_i386_invop, subcode=0x0) on dispatch_semaphore_dispose don't know how track downwards root cause of this. code makes utilize of dispatch_async, dispatch_group_enter , on.
update: cause of crash due fact webservicecall (see code below) never calls oncompletion , when code run again, got error exc_bad_instruction. verified indeed case, not sure why or how prevent this.
code:
dispatch_queue_t queue = dispatch_get_global_queue(dispatch_queue_priority_high, 0); dispatch_group_t grouping = dispatch_group_create(); (...) { if (...) { dispatch_group_enter(group); dispatch_async(queue, ^{ [self webservicecall:url oncompletion:^{ dispatch_group_leave(group); }]; }); } } dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{ dispatch_group_wait(group, dispatch_time(dispatch_time_now, (int64_t)(2.0 * nsec_per_sec))); dispatch_sync(queue, ^{ // phone call completion handler passed in caller }); });
from stack trace, exc_bad_instruction (code=exc_i386_invop, subcode=0x0)
occurred because dispatch_group_t
released while still locking (waiting dispatch_group_leave
).
according found, happened :
dispatch_group_t group
created. group
's retain count = 1. -[self webservice:oncompletion:]
captured group
. group
's retain count = 2. dispatch_async(...., ^{ dispatch_group_wait(group, ...) ... });
captured group
again. group
's retain count = 3. exit current scope. group
released. group
's retain count = 2. dispatch_group_leave
never called. dispatch_group_wait
timeout. dispatch_async
block completed. group
released. group
's retain count = 1. you called method again. when -[self webservice:oncompletion:]
called again, old oncompletion
block replaced new one. so, old group
released. group
's retain count = 0. group
deallocated. resulted exc_bad_instruction
. to prepare this, suggest should find out why -[self webservice:oncompletion:]
didn't phone call oncompletion
block, , prepare it. create sure next phone call method happen after previous phone call did finish.
in case allow method called many times whether previous calls did finish or not, might find hold group
:
dispatch_time_forever
or reasonable amount of time -[self webservice:oncompletion]
should phone call oncompletion
blocks time. block in dispatch_async(...)
hold you. or you can add together group
collection, such nsmutablearray
. i think the best approach create dedicate class action. when want create calls webservice, create object of class, phone call method on completion block passing release object. in class, there ivar of dispatch_group_t
or dispatch_semaphore_t
.
ios objective-c exception grand-central-dispatch
No comments:
Post a Comment