• 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: Integrating NSOutputStream and NSOperation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Integrating NSOutputStream and NSOperation


  • Subject: Re: Integrating NSOutputStream and NSOperation
  • From: Motti Shneor <email@hidden>
  • Date: Fri, 13 Nov 2015 16:38:52 +0200

Hello Jens, and thanks for the very useful information.

I still don't quite understand how to employ CFWriteStreamSetDispatchQueue. Can an NSOperation somehow obtain the dispatch_queue on which it is running?

I know NSOperationQueue has an accessor for its underlying dispatch_queue, but actual NSOperations are spawned in arbitrary threads - so I'm not sure about their dispatch_queue (if they run on a dispatch_queue at all). 

Supposedly I'd schedule my output stream on the OperationQueue's dispatch_queue. What kind of synchronization can I expect? Does this promise that stream events won't happen concurrently as my NSOperation's main()?

Also - If I need to reschedule the stream to each operation's dispatch_queue (provided they can each have a different one) is it advisable to reschedule a stream mid-running? how costly this is? Can I lose events that way?


However - my original hesitation remains - 

On 11 בנוב 2015, at 18:53, Jens Alfke wrote:


On Nov 11, 2015, at 3:46 AM, Motti Shneor <email@hidden> wrote:

If I (upon starting my operation) schedule the outputStream on the current operation’s runloop like thus:

    [self.outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

That won’t work because dispatch queues (other than main) and NSOperationQueues don’t have runloops. (If you call +currentRunLoop you do create a new runloop for whatever thread the queue is using, but that runloop won’t do anything because there’s no outer loop on that thread servicing it.)

If I can change the outputStream’s scheduling to use the same of my currently running operation - that should solve my synchronizing problem. My operation can bail safely, and be re-called on its own thread, without concurrency.

You can use CFWriteStreamSetDispatchQueue to schedule the stream on a queue instead of a runloop.

—Jens

Motti Shneor, 

CEO,  suMac LTD.

Software Development for the Macintosh


Home/Office Address: 34 Emek-Ha-Ella St. Appt.1 Modiin, ISRAEL, 71723

Home/Office Tel/Fax: +972-8-9267730

Home eMail: email@hidden Office eMail: email@hidden
Mobile phone: +972-54-3136621

---

ceterum censeo microsoftiem delendam esse

---











 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Integrating NSOutputStream and NSOperation
      • From: Jens Alfke <email@hidden>
References: 
 >Integrating NSOutputStream and NSOperation (From: Motti Shneor <email@hidden>)
 >Re: Integrating NSOutputStream and NSOperation (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Obtaining SSID string in iOS 9
  • Next by Date: To "Turbo3" on the forums
  • Previous by thread: Re: Integrating NSOutputStream and NSOperation
  • Next by thread: Re: Integrating NSOutputStream and NSOperation
  • Index(es):
    • Date
    • Thread