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

  • Home
  • SEARCH
  • 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 3333088
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:45:29+00:00 2026-05-17T23:45:29+00:00

In a Cocoa app, I have a setup like this: The main thread (M)

  • 0

In a Cocoa app, I have a setup like this:

  1. The main thread (M) can submit requests to a some background “producer” thread (B) to get some work done, say the result of a computation on item X.
  2. A different background thread (C) shortly thereafter might want the results of computing item X, and want those results synchronously.

Thread C could just re-do the work synchronously itself, but if thread B happens to be in the middle of computing item X already, I would like thread C to block and get the results from B. The results of the computation are findable on disk, so the data passing is not the issue.

What’s the best way of blocking thread C until thread B is done with item X?

Note that there the items that B processes are arbitrary– X is just one of many items in this example. I’d want to block until specifically item X is done.

So conceptually what I’d like is a way of thread B setting up some sort of flag when it starts saying “I’m working on X”, and if C comes in and sees that flag, it waits for the flag to clear, and then gets the result.

Not sure if I can somehow shoehorn NSLocks into this role, or if there’s a better primitive in the OS.

Any thoughts (or potential reframing of the problem) welcome! Thanks.

  • 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-17T23:45:29+00:00Added an answer on May 17, 2026 at 11:45 pm

    If possible, use NSOperation. It has a -waitUntilFinished method to allow for synchronous computation. You’d just need some thread-safe storage mechanism to allow you to find the NSOperation for the item you’re computing, if it already exists—say, an NSLock guarding an NSDictionary.

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

Sidebar

Related Questions

My Cocoa app needs some small dynamically generated windows. How can I programmatically create
I have a Cocoa app that uses a WebView to display an HTML interface.
I have a cocoa app with two types windows each of which requires a
I have a Cocoa app I'm writing that has an ImageView with a TextView
I'm adding repeating events to a Cocoa app I'm working on. I have repeat
Interface Builder can be used for basic dependency injection in a Cocoa app, but
I'm hacking on a simple Cocoa app to make blocks move around the screen
The situation I'm trying to solve: in my Cocoa app, I need to encrypt
I'm working on a Cocoa Mac app where I need to display a window/view
In Cocoa, NSTextView has a rather shallow margin between text and border. Is there

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.