• 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
Re: Threading!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Threading!


  • Subject: Re: Threading!
  • From: John Saccente <email@hidden>
  • Date: Tue, 19 Mar 2002 16:05:41 -0600

Try using oneway:

By default, messages sent to a proxy object are forwarded over the connection synchronously; that is, the sender waits for the message to be processed and a reply received from the remote object. This occurs even for a method with a void return type, since the remote object can raise an exception that is passed back to the sender. The local thread or application thus blocks until the message completes execution. To avoid this, you can declare the method type as oneway void to cause asynchronous messaging. For more details, see Inside Cocoa: Objective-Oriented Programming and the Objective-C Language.

from:

<http://developer.apple.com/techpubs/macosx/Cocoa/TasksAndConcepts/ProgrammingTopics/
DistrObjects/Tasks/accessing.html>

See the SimpleThreads and TrivialThreads sample code.

John Saccente
email@hidden

On Tuesday, March 19, 2002, at 02:24 PM, Steven Frank wrote:

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

_______________________________________________
MacOSX-dev mailing list
email@hidden
http://www.omnigroup.com/mailman/listinfo/macosx-dev
_______________________________________________
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.

References: 
 >Threading! (From: Steven Frank <email@hidden>)

  • Prev by Date: Arrow keys
  • Next by Date: Re: over-riding the behaviour of the tab key in a NSTextView
  • Previous by thread: Threading!
  • Next by thread: Re: Threading!
  • Index(es):
    • Date
    • Thread