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 991723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:09:16+00:00 2026-05-16T06:09:16+00:00

What I Want I’ve got an NSOperationQueue in my application and it’s critical that

  • 0

What I Want

I’ve got an NSOperationQueue in my application and it’s critical that all operations get processed before the application quits. I’ve got the following code on quit to make sure the NSOperationQueue is empty before quitting:

if ([NSThread isMainThread]) {
    while ([[operationQueue operations] count] > 0) {
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]];
    }
} else {
    [operationQueue waitUntilAllOperationsAreFinished];
}

I’ve encountered a problem with my code before where an NSOperation “froze” before finishing and it blocked the whole queue. Obviously, in situations like this, my code should throw an exception, which it now does.

But I still want to guard against anything weird happening where operations stop and block the queue, resulting in the application never quitting and the fault not being caught.

My Rubbish Solution

I’m considering putting a timeout on the queue finishing its operations. Then when it does timeout, I could throw an exception then the problem could be caught.

However, this doesn’t feel right. Ideally, I don’t want to be reliant upon timers to make sure work is done.

My Question

Is there a better, fail safe, way of making sure my operations haven’t frozen?

  • 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-16T06:09:17+00:00Added an answer on May 16, 2026 at 6:09 am

    If I understand…

    • you want to know that your operations haven’t frozen … becomes …
    • you want to know that all of your operations will finish executing … becomes …
    • you want to solve the halting problem

    Good luck with that.

    Realistically though, what you’re doing with the waitUntilAllOperationsAreFinished is about as good as you’re going to get. You could add another class that watches each operation and makes sure it doesn’t run for too long (say 10x longer than you’re expecting it to run), at which point it would -cancel the NSOperation (More or less your timer approach). However, even that’s not foolproof, because the operation could be blocked on something where you can’t check for -isCancelled (inside a system call, for example).

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

Sidebar

Related Questions

Want an applescript droplet that opens files in QuickTime and mutes them all. The
want to get all db entries by a specific hash and return it as
Want to add following feature to my web application: To decode barcodes generated by
Want to make sure I got that right: Base SDK = What you're building
Want to code a key pad for an calculator. What I want to make
Want to send the text from my current vb application to the Active Window
Want to develop a query refinement tool just like Google Suggest so that i
want to make a check in my installer before starting installation if any other
want to create a temporary table that has an auto_increment field plus a field
Want to verify that my understanding of how this works. Have a C++ Class

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.