Thread safety of NSPipe
Thread safety of NSPipe
- Subject: Thread safety of NSPipe
- From: Glen Low <email@hidden>
- Date: Wed, 18 Feb 2004 22:12:13 +0800
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.)
Cheers, Glen Low
---
pixelglow software | simply brilliant stuff
www.pixelglow.com
_______________________________________________
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.