• 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: Thread safety of NSPipe
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Thread safety of NSPipe


  • Subject: Re: Thread safety of NSPipe
  • From: Shawn Erickson <email@hidden>
  • Date: Wed, 18 Feb 2004 08:27:30 -0800

On Feb 18, 2004, at 6:12 AM, Glen Low wrote:

Dear all,

According to

http://developer.apple.com/documentation/Cocoa/Conceptual/
Multithreading/Tasks/foundation.html

the classes NSPipe and NSFileHandle are not "thread-safe". However, the
definition of thread-safe is perhaps a little loose and more
object-oriented than the typical: it says "able to have operations
invoked simultaneously by multiple threads of execution on an
instance...". Does this mean that operations can be invoked on separate
instances of any class in different threads?

For example, consider a class that uses a static variable (shared
data). Then invoking an operation on two separate instances on two
separate threads might cause contention for the static variable, if it
is not locked properly.

Now for the practical question:

Can NSPipe and NSFileHandle, not "threadsafe" within an instance, be
"threadsafe" between different instances?

Consider the following scenario:

1. Main thread creates an NSPipe.
2. Main thread creates a writing NSFileHandle.
3. Main thread creates a reading NSFileHandle and detaches a worker
thread, passing it the NSFileHandle.
4. Main thread writes to the writing NSFileHandle.
5. Worker thread reads from the reading NSFileHandle.

Am I going to get corrupted data? In all cases, operations are
performed on different threads on different objects. (Deallocating the
NSPipe seems problematic, but if it is a static variable, it doesn't
need to get deallocated.)

I believe it is thread safe in the sense that you will be using.

I bet the non-thread safe wording is in relation to multiple threads writing to the pipe or reading from it. In the above you have a simple producer consumer setup using a pipe for communication (one writer one reader), that should work as I understand standard pipe behavior.

-Shawn
_______________________________________________
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: 
 >Thread safety of NSPipe (From: Glen Low <email@hidden>)

  • Prev by Date: Re: Debugging Bindings in Cocoa
  • Next by Date: Re: mmalc's Controller examples
  • Previous by thread: Thread safety of NSPipe
  • Next by thread: Special behavior when double-click NSTableView cell
  • Index(es):
    • Date
    • Thread