• 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: DO Connections
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: DO Connections


  • Subject: Re: DO Connections
  • From: Douglas Davidson <email@hidden>
  • Date: Wed, 30 Oct 2002 12:31:47 -0800

On Tuesday, October 29, 2002, at 05:34 PM, Anthony Duer wrote:

I think I've found the reason why a NSThread that listens on a socket using a simple while loop is causing drawing problems. I thought posting a NSNotification would have that data safely exit the secondary thread to a thread where it's safe to draw to the screen from. Apparently not. Thus, I've decided to move my NSThread into a separate class and have a DO connection link back to main thread. However, the main stickler is this: If the separate class running my second NSThread is locked into a continuous while loop, how can the main thread inform the secondary thread that the socket is supposed to close? Is there a way to share a memory address for a BOOL and safely have both threads access it?

There are many ways you can communicate between threads. You can use an NSLock to protect access to data structures in memory. You can use an NSConditionLock for communicating simple values. You could add an additional socket to your select() (if you're using select()) and have the main thread send to it. You might even just be able to close() the socket from the main thread, although that seems a bit crude. Many other possibilities suggest themselves; personally I would prefer to forgo the secondary thread and use a CFSocket or CFStream as a run loop source, and use that to listen on the socket in the main thread's run loop.

Douglas Davidson
_______________________________________________
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: 
 >DO Connections (From: Anthony Duer <email@hidden>)

  • Prev by Date: Re: XML-/HTML-safe formatted output from NSString
  • Next by Date: Re: Syntax-coloring NSTextView
  • Previous by thread: DO Connections
  • Next by thread: Re: DO Connections
  • Index(es):
    • Date
    • Thread