• 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: NSDistributedLock question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDistributedLock question


  • Subject: Re: NSDistributedLock question
  • From: BK <email@hidden>
  • Date: Wed, 19 Apr 2006 14:56:12 -0700


On Apr 19, 2006, at 2:39 PM, Shaun Wexler wrote:

On Apr 19, 2006, at 12:51 PM, Bill wrote:

I'm having some trouble using NSDistributedLock, and maybe someone can shed some light.
In the Finder, I first create a new sample text file on my hard disk. My application then does this:


// filename is the path to the text file I just created
NSDistributedLock *myLock = [[NSDistributedLock alloc] initWithPath:filename];
// this works fine


NSDate *date = [myLock lockDate];
// I just created the sample text file, yet the NSDate returned is valid. Who locked the file?

You did, because you created it, and as the owner you are holding the mutex now.

I hold the mutex after I create, save and close the file using TextEdit, before I even run my app?



BOOL success = [myLock tryLock];
// this fails. Who has locked this file I just created? The File Manager?

You were holding the lock already. It's not recursive.

[myLock unlock];
// calling this causes the file to disappear (deleted?)!

Yep.

Not sure yet I understand why it gets deleted. I simply want to lock an existing file, write to it, and then unlock it.



Can anyone tell me what's going on, or what I'm doing wrong?
Thanks!
Bill

If any other process tries to [create/access] the lock (ie a file with that pathname), and it already exists, it will obey normal mutex semantics and use the existing lock; if it choses to block on that mutex [myLock lock] it will remain blocked until the current process which holds the lock releases it, and once it obtains the lock, it will unblock and continue. When no processes are holding or trying to obtain the lock, the file is deleted, atomically.

Except that lock: is not a NSDistributedLock method.

--
Shaun Wexler
MacFOH
http://www.macfoh.com

Thanks, Bill


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: NSDistributedLock question
      • From: Shaun Wexler <email@hidden>
References: 
 >NSDistributedLock question (From: "Bill" <email@hidden>)

  • Prev by Date: Re: NSDistributedLock question
  • Next by Date: Re: NSDistributedLock question
  • Previous by thread: Re: NSDistributedLock question
  • Next by thread: Re: NSDistributedLock question
  • Index(es):
    • Date
    • Thread