• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Threading!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Threading!


  • Subject: Threading!
  • From: Steven Frank <email@hidden>
  • Date: Tue, 19 Mar 2002 12:24:21 -0800

There are clearly still huge gaps in my understanding of how threading works in Cocoa.

In my app, I have set up almost exactly what is described here:

http://developer.apple.com/techpubs/macosx/Cocoa/TasksAndConcepts/ProgrammingTopics/
Multithreading/Tasks/connections.html

There's a main thread for handling the GUI, and a worker thread sitting in a runloop. I can call methods in both directions, it all works fine.

But when the main thread calls a method on the worker thread via the NSConnection, it _waits_ for it to return, which defeats the whole purpose of threading in the first place. What's the point of detaching a thread if it runs synchronously?

Specifically, here's what I'm trying to accomplish...

- A main thread, servicing the GUI

- One or more child threads, each managing a single network connection using blocking socket calls.

For example, imagine a document-based app where each document window has a persistent network connection associated with it. I want the document (in the main thread) to tell its associated child network thread to connect to some host. I DON'T want the main thread to block waiting for the socket connection to finish, I just want a message back later from the child thread that it either connected or it didn't.

Furthermore, if the user indicates they want to abort the connection, I need a way to communicate that to the thread.

I can't just use plain NSThreads and NSNotifications, because this is not thread safe. So, I switched to NSConnection, which has given me thread-safe message passing, but blocks until the remote call completes. So, now I don't know what to do.

There must be someone out there that knows how to do this correctly.

Thank you,

Steven
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Threading!
      • From: John Saccente <email@hidden>
  • Prev by Date: over-riding the behaviour of the tab key in a NSTextView
  • Next by Date: Code for a Control with a continuous action
  • Previous by thread: Re: over-riding the behaviour of the tab key in a NSTextView
  • Next by thread: Re: Threading!
  • Index(es):
    • Date
    • Thread