On Apr 24, 2014, at 10:14 PM, Jens Alfke wrote: > I’m writing an Objective-C API around a database library, and trying to add > some optimizations. There’s a lot of room for parallelizing, since tasks like > indexing involve a combination of I/O-bound and CPU-bound operations. As a > first step, I made my API thread-safe by creating a dispatch queue and > wrapping the C database calls in dispatch_sync blocks.
You may be aware of this, but dispatch_sync() is not necessary or even particularly relevant to thread-safety. The use of a serial queue or, possibly, a reader/write mechanism using barriers, is what achieves thread safety. Using a synchronous call is only necessary if your API has synchronous semantics. For example, if a call provides immediate results to the caller. Reading from a database would typically have to be synchronous, but writing to it can often be asynchronous. All you care about is that future reads will always see what was previously written, which the serial queue or barriers will guarantee. That doesn't necessarily have any bearing on the overhead of GCD vs. the resources of an iPhone, but I thought I'd point it out. Regards, Ken _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com