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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:42:03+00:00 2026-06-10T05:42:03+00:00

I am newcomer in Objective C. I have an object, that creates new thread

  • 0

I am newcomer in Objective C.
I have an object, that creates new thread via GCD with dispatch_async in default queue.
I use dispatch_semaphore_wait with timeout = 1sec in thread to check when I need to close this thread.

When i call “close” method, it send dispatch_semaphore_signal and thread closes. But sometimes thread lives some time after “close” method ended. How could I wait in my “close” method until thread ends?

Thx.

  • 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-10T05:42:04+00:00Added an answer on June 10, 2026 at 5:42 am

    Canonical answer to such a question: What are you trying to do?

    I ask this because, first, you should neither need to know or care that there is a thread backing a GCD request and when it exits – that’s entirely up to GCD to manage.

    Second, you should always be suspicious of code that uses explicit timeouts (other than “FOREVER”). If you have any reason to ask yourself “Why 1 second? What happens if whatever event I’m waiting for takes more or less time than this?” then you are engaging in the kind of thinking that leads to polling, and polling is just BAD BAD (evil, wrong) design for pretty much everything but writing certain kinds of device drivers!

    A far more reasonable approach is to use a completion callback at the end of your operation to signal that it’s done, taking a fully async approach to programming and also following, in the process, one of the fundamental design principles of GCD.

    It sounds to me, and I’m just guessing here, that you’re taking an existing programming paradigm or way of thinking and erroneously applying it to GCD. An understandable mistake, but a mistake nonetheless.

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

Sidebar

Related Questions

I'm a newcomer to PDO and have to say that I like it so
I'm running into an import issue that as a relative newcomer to the Objective-C/C++/XCode
I have a std::vector<std::string> that I need to use for a C function's argument
I'm a Go newcomer, but I have read that Go regulars do not miss
As a newcomer to iOS, I found that ARC has thus far really helped
I'm a newcomer to Rails, and have been following the tutorial on the rails
I'm a newcomer to Rails. I want to build a simple form that determines
I'm a newcomer to Python but I understand that things should not be done
Newcomer to Objective C and trying to translate concepts and sytax I know from
(I am a relative newcomer to TortoiseHg, so bear with me :-) I use

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.