On Dec 22, 2008, at 10:30 AM, Kyle Sluder wrote:

Nowhere does the documentation say this.  You can't call -[NSLock
lock] multiple times, because you'll block on a lock you already have
(that's why we have recursive locks).  Otherwise -[NSLock tryLock]
would be quite useless, wouldn't it?

Maybe I misinterpreted, but from the first page of NSLock:

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSLock_Class/Reference/Reference.html

"You should not use this class to implement a recursive lock. Calling the lock method twice on the same thread will lock up your thread permanently. Use the NSRecursiveLock class to implement recursive locks instead."


From the questions you're asking, it sounds like you're going to
implement a spinlock on top of NSLock.  Don't do this.  Just use
@synchronized.

Problem is, I'm a thread noob so have no idea which type of lock is right for my situation. As to @synchronized, Robert Marini seemed to suggest that that was a Leopard-pnly solution. This app has to work on Tiger as well.

Basically here's the scenario:

The app has a small number of user defined root watch folders. Each root folder spawns it's own watcher. When the root folder timer fires, It tells all it's child watchers to check their contents for changes. If a directory was inserted into one of the subdirectories, a new watcher is created and added to the root watcher list. The root watcher is the only one that initiates update messages for it's subfolders but the subfolders can add or remove items from it.

Given that, could you give a really simple example of how to coordinate access between the three methods? @synchronized may be the way to go but it doesn't explain how one method could determine busy status and wait for an opening before doing its thing.

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to