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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:15:26+00:00 2026-06-04T16:15:26+00:00

This could be a much more generic question abut how to best cancel blocking

  • 0

This could be a much more generic question abut how to best cancel blocking jobs on other threads, but I’m interested in a solution in the context of Grand Central Dispatch. I have the need to call a function which basically blocks until it gets data from the network; it could potentially be blocked forever. I have it set up now so that this blocked call happens on a private dispatch queue, and when i do get data, i put a block back on the main queue. Th e problem is that once I dispatch my private-queue-block and blocking call, I can never really cancel that. Imagine this ability was tied to a user setting toggle. If they toggled off, I would want this blocking job and execution block to essentially just end. Is there a good solution to this type of problem?

Thanks

- (void)_beginListeningForNetworkJunk
{
    dispatch_async(my_private_queue, ^{
        // blocks until it gets data
        id data = [NetworkListener waitForData];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self _handleNetworkData:data];
        });
    });
}

- (void)_endListeningForNetworkJunk
{
   // How do I kill that job that is blocked on my private queue?
}
  • 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-06-04T16:15:27+00:00Added an answer on June 4, 2026 at 4:15 pm

    You can’t. The problem is in NetworkListener in its blocking-and-uninterruptible interface.

    Normally, you’d code the block to service the network connection asynchronously and also monitor some other signalling mechanism, such as a custom run loop source (or NSPort or pipe file descriptor or …). When the network connection had activity, that would be serviced. When the signalling mechanism fired, you would shut down the network connection and exit the block.

    In that way, the block could be cancellable with its cooperation.

    Since your block is stuck in -waitForData, it can’t cooperate. There’s no mechanism for canceling blocks without their cooperation. The same is true of NSOperation and NSThread. The reason is that it’s basically infeasible to terminate another thread’s activity without its cooperation.

    You need a different design for your networking code.

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

Sidebar

Related Questions

This could be an amazingly dumb question, but .... I don't think a standard
I'm specifically referring to JavaScript anonymous function but this could be relevant to other
This could save me so much time. Sometimes I find myself writing things like
This could quite possibly be the dumbest question ever asked. Our client wants us
This could be considered a duplicate question, as a similar one has already been
I suppose this could apply to any dynamic language, but the one I'm using
I don't think that this could be done in C#, but posting this just
I'm quite new to vb.net as I'm much more of a PHP developer but
I couldn't come up with anything on Google, but this is a question I've
I am wondering whether this could be worse parallelizing generation of random numbers. I

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.