Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7589591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:11:58+00:00 2026-05-30T20:11:58+00:00

I’m trying to cancel and then release a suspended timer but when I invoke

  • 0

I’m trying to cancel and then release a suspended timer but when I invoke ‘dispatch_release’ on it, I immediately get EXC_BAD_INSTRUCTION.

Is this not a valid set of actions to take on a timer?

Timer creation & suspension:

@interface SomeClass: NSObject { }
@property (nonatomic, assign) dispatch_source_t             timer;
@end

// Class implementation
@implementation SomeClass

@synthesize timer = _timer;

- (void)startTimer 
{
    dispatch_queue_t globalQ = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 
                                    0, 0, globalQ); 

    dispatch_time_t startWhen = dispatch_walltime(DISPATCH_TIME_NOW, NSEC_PER_SEC * 1);
    dispatch_source_set_timer(_timer, startWhen, 1 * NSEC_PER_SEC, 5000ull);

    dispatch_source_set_event_handler(_timer, ^{
        // Perform a task 

        // If a particular amount of time has elapsed, kill this timer
        if (timeConstraintReached)
        {
            // Can I suspend this timer within it's own event handler block?
            dispatch_suspend(_timer);
        }
    });

    dispatch_resume(_timer);
}

- (void)resetTimer
{
    dispatch_suspend(_timer);

    dispatch_source_cancel(_timer);

    // dispatch_release causes 
    // 'EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    dispatch_release(_timer);

    self.timer = nil;    
}
@end

Additionally, can I invoke dispatch_suspend within a timer source’s event_handler block?

Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:11:59+00:00Added an answer on May 30, 2026 at 8:11 pm

    The reason it crashes is because of this code:

    void
    _dispatch_source_xref_release(dispatch_source_t ds)
    {
        if (slowpath(DISPATCH_OBJECT_SUSPENDED(ds))) {
            // Arguments for and against this assert are within 6705399
            DISPATCH_CLIENT_CRASH("Release of a suspended object");
        }
        _dispatch_wakeup(ds);
        _dispatch_release(ds);
    }
    

    So, you can’t release a dispatch_source_t that has been suspended. You probably want to just not suspend it in resetTimer I guess.

    Whilst I can’t find anything in the docs for why they have written it like this (and the comment alludes to the pros and cons being in a radar we’ll never see), all I can do is refer to the docs where it says:

    You can suspend and resume the delivery of dispatch source events
    temporarily using the dispatch_suspend and dispatch_resume methods.
    These methods increment and decrement the suspend count for your
    dispatch object. As a result, you must balance each call to
    dispatch_suspend with a matching call to dispatch_resume before event
    delivery resumes.

    Whilst that doesn’t say you can’t release a dispatch source that’s been suspended, it does say you have to balance each call so I’m assuming it’s something along the lines of it’s using a dispatch semaphore under-the-hood which have to be balanced before they can be released. That’s just my guess though :-).

    As for “can I invoke dispatch_suspend within a timer source’s event_handler block”. I’m pretty sure you can, yes, as per the docs for dispatch_suspend:

    The suspension occurs after completion of any blocks running at the time of the call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.