Localization of Help
A weird issue this. I'm trying to Localize my app - and, mostly, it's worked like a charm. For some reason though, the help always gets delivered in the English version. I have tried reindexing the help files - and now I'm out of ideas (Google wasn't much help either!). Can anyone point me to a good resource on problems with Localizing help files - or even, perhaps, suggest what the problem might be? Regards, Pascal ___ 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
Re: Localization of Help
On 12/7/12 2:34 PM, Pascal Harris wrote: A weird issue this. I'm trying to Localize my app - and, mostly, it's worked like a charm. For some reason though, the help always gets delivered in the English version. I have tried reindexing the help files - and now I'm out of ideas (Google wasn't much help either!). Can anyone point me to a good resource on problems with Localizing help files - or even, perhaps, suggest what the problem might be? If you're building a help bundle, what you absolutely must have in order to get help pick up your localized version is (for each individual localization) a InfoPlist.strings containing (at a minimum) HPDBookTitle = ""; Without this, you'll always get the development language. Regards Markus -- __ Markus Spoettl ___ 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
leak in AVAudioPlayer ?
Hi, I have seen in leaks profiler the AVAudioPlayer make three retain and only two release of NSURL -- best regards Ariel ___ 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
Create a socket.io connection to node.js server
Hi there, I want to create a socket.io tube between my iOS app and my server who's running on node.js, I want to implement it for getting some now.js method and get many many feature like my web page and my native app. I tried CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef)@"neventy.fr", 80, &readStream, &writeStream); But it seems it doesn't work… I get 4 stream event (1 and 2) and after 3 event I get stream event 2 and 4. I don't know why and how I can connect to my node.js server :/ Do you have an idea ? Thanks for your help. Cheers, Vavelin Kévin Twitter | Blog | LinkedIn Entrepreneur Developer OS X / iOS ___ 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
Re: Localization of Help
Top advice - and one step closer. I now have help in English and in Spanish. Sadly, my French help is also in Spanish - which is rather confusing! On 7 Dec 2012, at 13:54, Markus Spoettl wrote: > On 12/7/12 2:34 PM, Pascal Harris wrote: >> A weird issue this. I'm trying to Localize my app - and, mostly, it's worked >> like a charm. For some reason though, the help always gets delivered in the >> English version. I have tried reindexing the help files - and now I'm out of >> ideas (Google wasn't much help either!). Can anyone point me to a good >> resource on problems with Localizing help files - or even, perhaps, suggest >> what the problem might be? > > If you're building a help bundle, what you absolutely must have in order to > get help pick up your localized version is (for each individual localization) > a InfoPlist.strings containing (at a minimum) > > HPDBookTitle = ""; > > Without this, you'll always get the development language. > > Regards > Markus > -- > __ > Markus Spoettl > ___ > > 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/45rpmlists%40googlemail.com > > This email sent to 45rpmli...@googlemail.com ___ 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
Align attributed string to baseline
Hi, I am getting serious difficulties at drawing an attributed string within an attachmentCell and get it aligned on the baseline. I have a NSTextView. I add an attachment with its attachmentCell. In the method cellFrameForTextContainer I return a cell.frame.height = font.ascender - font.descender; In the method drawWithFrame: of the cell, I draw the string with drawAtPoint: cellFrame.origin.x, cellFrame.origin.y - font.descender; It works well with some font and size: the attachment string is aligned with the rest of the text (with same font and size) in the NSTextView. E.g. with Futura Medium >= 17 the string is "always" aligned. But with Futura Medium < 18 the string goes lower than the baseline. Why? What do I miss there? Regards -- Leonardo ___ 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
Re: leak in AVAudioPlayer ?
On Dec 7, 2012, at 6:23 AM, Ariel Feinerman wrote: > I have seen in leaks profiler the AVAudioPlayer make three retain and only > two release of NSURL Could you share a minimal amount of code that reproduces this leak? -- David Duncan ___ 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
Re: Create a socket.io connection to node.js server
On Dec 7, 2012, at 6:25 AM, Kévin Vavelin wrote: > I tried CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, > (CFStringRef)@"neventy.fr", 80, &readStream, &writeStream); > > But it seems it doesn't work… I get 4 stream event (1 and 2) That tells you the input and output streams are opening, and then opened. That’s good. > and after 3 event I get stream event 2 and 4. Sounds fine. 4 is kCFStreamStatusWriting which tells you you can write to the output stream without blocking. Are you writing anything? I don’t know how socket.io works, but it’s likely that the server is waiting for you to send it something before it will send you a response. Apple has sample apps that show how to use CFStreams (and NSStreams) for TCP. BTW, if you prefer using Objective-C you can simply case the CFStreamRefs returned by the Create call to NSInputStream* and NSOutputStream*, and then do everything else using the NSStream API. —Jens ___ 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
Help Book icon — retina?
Apple's Help Book documentation suggests using a 16x16 icon for the icon pointed to by HPDBookIconPath: https://developer.apple.com/library/mac/documentation/Carbon/Conceptual/ProvidingUserAssitAppleHelp/authoring_help/authoring_help_book.html#//apple_ref/doc/uid/TP3903-CH206-CIHDHGCJ However, this will obviously be far too small on a Retina Display. So, I'm wondering what the current best practice is: 1. What size should we be using now for the HPDBookIconPath icon? Intuition would suggest 32x32, since that would be double the old guidelines, but Safari, Mail, and iTunes all seem to be using 64x64 icons. 2. Is there any way to specify separate icons for retina and non-retina resolutions? Does the icon.png and i...@2x.png trick work here, or should I just resign myself to giving the non-retina users a blurry icon? Thanks, Charles ___ 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
Re: Create a socket.io connection to node.js server
Yes I understand, I use NSInputStream and NSOutputStream for writing something but I don't know why I have my stream closed after an event hasSpaceAvailable or something like that. Here's my code and I send nothing to my stream. - (void) initNetworkCommunication { CFReadStreamRefreadStream = nil; CFWriteStreamRefwriteStream = nil; CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef)@"neventy.fr", 80, &readStream, &writeStream); inputStream = (NSInputStream *)readStream; outputStream = (NSOutputStream *)writeStream; [inputStreamsetDelegate:self]; [outputStreamsetDelegate:self]; [inputStreamscheduleInRunLoop:[NSRunLoopcurrentRunLoop]forMode:NSDefaultRunLoopMode]; [outputStreamscheduleInRunLoop:[NSRunLoopcurrentRunLoop]forMode:NSDefaultRunLoopMode]; [inputStream open]; [outputStream open]; } - (void)stream:(NSStream*)theStream handleEvent:(NSStreamEvent)streamEvent { NSLog(@"stream event %i", streamEvent); NSMutableData *_data; switch (streamEvent) { caseNSStreamEventNone: NSLog(@"Aucun event"); break; caseNSStreamEventOpenCompleted: NSLog(@"Stream opened"); break; caseNSStreamEventHasBytesAvailable: if(!_data) { _data = [[NSMutableData data] retain]; } uint8_tbuf[1024]; unsignedint len = 0; len = [(NSInputStream *)inputStreamread:buf maxLength:1024]; if(len) { [_data appendBytes:(const void*)buf length:len]; } else { NSLog(@"no buffer!"); } break; caseNSStreamEventHasSpaceAvailable : NSLog(@"Espace"); NSLog(@"%@",outputStream); break; caseNSStreamEventErrorOccurred: NSLog(@"Can not connect to the host!"); break; caseNSStreamEventEndEncountered: NSLog(@"Erreur"); [theStreamclose]; [theStreamremoveFromRunLoop:[NSRunLoopcurrentRunLoop]forMode:NSDefaultRunLoopMode]; [theStreamrelease]; theStream = nil; break; default: NSLog(@"Unknown event"); } } Vavelin Kévin Twitter | Blog | LinkedIn Entrepreneur Developer OS X / iOS ___ 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
Re: Help Book icon — retina?
On Dec 7, 2012, at 1:11 PM, Alex Zavatone wrote: > I think the general rule that the dimensions should be 2x the size of non > retina items. I know, but Apple's own Help Book icons all seem to be 64x64, which is 4x the size (in each dimension), not 2x, which is why I'm confused. Is there any sort of official word on what we should use now? Charles ___ 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
Re: How to implement readonly property
On Dec 7, 2012, at 7:03 AM, Jeremy Pereira wrote: > On 12 Nov 2012, at 20:45, Greg Parker wrote: >> There is something special about statically-allocated memory. >> Statically-allocated memory has always been zero for the life of the >> process. Dynamically-allocated memory may have been non-zero at some point >> in the past (i.e. if it was previously part of a now-freed allocation). >> >> The problem is your condition #2. If the memory was previously non-zero and >> you set it to zero, you need appropriate memory barriers on some >> architectures to prevent a race where the caller of dispatch_once() sees the >> old non-zero value. Neither dispatch_once() nor the malloc system nor the >> Objective-C runtime promise to provide the correct barriers. >> >> In some cases you might be able to add an appropriate memory barrier to your >> -init... method, assuming that no calls to dispatch_once() occur before >> then. >> >> In practice this is a difficult race to hit, but it's not impossible. > > Sorry, I'm a bit late to the party here but I've just read this and I don't > understand it. > > If this race condition really exists, you couldn't assume that *any* instance > variables of a newly initialised object have been zeroed out. > > What am I missing? Your statement is missing the additional requirements to hit the race: You can't assume that any instance variables of a newly initialized object have been zeroed out when * you are reading them from threads other than the one that allocated the object and * there is no synchronization between the allocating thread and the reading thread. In ordinary code there is only one thread involved, or there is already some thread synchronization somewhere. For example, the allocating thread acquires a lock before writing the new object's pointer somewhere that the reading thread can see it, and the reading thread takes the same lock before reading the object pointer. That lock is sufficient synchronization to make it work. You'll only run into trouble if you are trying to use lock-free multiprocessing techniques and you don't use enough memory barriers. -- Greg Parker gpar...@apple.com Runtime Wrangler ___ 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
Re: Create a socket.io connection to node.js server
On Dec 7, 2012, at 11:04 AM, Vavelin Kévin wrote: > Yes I understand, I use NSInputStream and NSOutputStream for writing > something but I don't know why I have my stream closed after an event > hasSpaceAvailable or something like that. But previously you said you get messages 2 and 4, which are NSStreamEventHasBytesAvailable and NSStreamEventHasSpaceAvailable (I was wrong in my earlier reply; was looking at the wrong set of constants.) The close/error events are 8 and 16. In any case, if your socket gets closed abruptly it’s often because the remote server didn’t like the message you sent and hung up on you, which is a protocol-specific issue. I don’t know anything about the socket.io protocol; you might have to ask on a node.js list for help with that. —Jens ___ 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
Re: How to implement readonly property
On Dec 7, 2012, at 3:08 PM, Greg Parker wrote: > On Dec 7, 2012, at 7:03 AM, Jeremy Pereira wrote: >> On 12 Nov 2012, at 20:45, Greg Parker wrote: >>> There is something special about statically-allocated memory. >>> Statically-allocated memory has always been zero for the life of the >>> process. Dynamically-allocated memory may have been non-zero at some point >>> in the past (i.e. if it was previously part of a now-freed allocation). >>> >>> The problem is your condition #2. If the memory was previously non-zero and >>> you set it to zero, you need appropriate memory barriers on some >>> architectures to prevent a race where the caller of dispatch_once() sees >>> the old non-zero value. Neither dispatch_once() nor the malloc system nor >>> the Objective-C runtime promise to provide the correct barriers. >>> >>> In some cases you might be able to add an appropriate memory barrier to >>> your -init... method, assuming that no calls to dispatch_once() occur >>> before then. >>> >>> In practice this is a difficult race to hit, but it's not impossible. >> >> Sorry, I'm a bit late to the party here but I've just read this and I don't >> understand it. >> >> If this race condition really exists, you couldn't assume that *any* >> instance variables of a newly initialised object have been zeroed out. >> >> What am I missing? > > Your statement is missing the additional requirements to hit the race: > > You can't assume that any instance variables of a newly initialized object > have been zeroed out when > * you are reading them from threads other than the one that allocated the > object and > * there is no synchronization between the allocating thread and the reading > thread. > > In ordinary code there is only one thread involved, or there is already some > thread synchronization somewhere. > > For example, the allocating thread acquires a lock before writing the new > object's pointer somewhere that the reading thread can see it, and the > reading thread takes the same lock before reading the object pointer. That > lock is sufficient synchronization to make it work. > > You'll only run into trouble if you are trying to use lock-free > multiprocessing techniques and you don't use enough memory barriers. But this means that dispatch_once() is not uniquely unsafe. It can fail only in the exact same scenarios where a thread other than the one which allocated an object might see uninitialized values for generic instance variables. Such scenarios are, of course, unacceptable and so proper synchronization is necessary when passing object pointers between threads, full stop. There's no special care necessary to make dispatch_once() safe, there's just the ordinary care necessary to make passing of object pointers between threads "sane". You said that dispatch_once() doesn't promise to provide memory barriers, but, since the use of GCD hasn't brought catastrophe down on all of our heads, I assume that dispatch_async() and the like do provide such memory barriers. Likewise, NSOperationQueue, -performSelector:onThread:..., and the like must also. Is that right? If you wanted to be paranoid about using an instance variable as a once predicate, is it sufficient to use OSMemoryBarrier() in the -init method of the object? Or perhaps there needs to be another call to OSMemoryBarrier() immediate before the dispatch_once() call, too. 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
Re: Align attributed string to baseline
On 7 Dec 2012, at 17:40, Leonardo wrote: > Hi, > I am getting serious difficulties at drawing an attributed string within an > attachmentCell and get it aligned on the baseline. > I have a NSTextView. I add an attachment with its attachmentCell. > In the method cellFrameForTextContainer I return a >cell.frame.height = font.ascender - font.descender; > In the method drawWithFrame: of the cell, I draw the string with > drawAtPoint: cellFrame.origin.x, cellFrame.origin.y - font.descender; > It works well with some font and size: the attachment string is aligned with > the rest of the text (with same font and size) in the NSTextView. > E.g. with Futura Medium >= 17 the string is "always" aligned. > > But with Futura Medium < 18 the string goes lower than the baseline. Why? > What do I miss there? Try using the following method instead: -drawWithRect:options:attributes: See Aki Inoue's explanation in http://lists.apple.com/archives/cocoa-dev/2012/Sep/msg00442.html -drawAtPoint uses a different layout strategy that can have these sort of effects. Jonathan ___ 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
Re: Remote control desktop from iPhone
It's not directly what you need, but NSLogger might be worth looking at. It sends realtime logs from an iOS device to the desktop: https://github.com/fpillet/NSLogger On Thu, Dec 6, 2012 at 10:59 AM, Eric E. Dolecki wrote: > I'm about to embark on a local project that requires an iOS app to be able > to send string commands to a running OS X application. Essentially a remote > control for the OS X app. > > Without having to do a lot of research and the banging of my head against > the fact that there is currently no way to use GameKit on OS X to comm with > an iOS app using GameKit, is there a known project on github or elsewhere > that simply sets this stuff up? I realize it may require a socket server or > something - but I am no networking/Bonjour guru. > > Looking for the communication stuff if I can find it so I can concentrate > on what I'll be doing with it instead. > > Any known stuff out in the wild I might be able to use? I'll be Googling > and StackOverflow'ing in the mean time. > > Thanks for any help, > Eric > ___ > > 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/websites%40paperetto.com > > This email sent to websi...@paperetto.com > -- David Brittain da...@paperetto.com ___ 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
Re: How to implement readonly property
On 12 Nov 2012, at 20:45, Greg Parker wrote: > > > There is something special about statically-allocated memory. > Statically-allocated memory has always been zero for the life of the process. > Dynamically-allocated memory may have been non-zero at some point in the past > (i.e. if it was previously part of a now-freed allocation). > > The problem is your condition #2. If the memory was previously non-zero and > you set it to zero, you need appropriate memory barriers on some > architectures to prevent a race where the caller of dispatch_once() sees the > old non-zero value. Neither dispatch_once() nor the malloc system nor the > Objective-C runtime promise to provide the correct barriers. > > In some cases you might be able to add an appropriate memory barrier to your > -init... method, assuming that no calls to dispatch_once() occur before then. > > In practice this is a difficult race to hit, but it's not impossible. > Sorry, I'm a bit late to the party here but I've just read this and I don't understand it. If this race condition really exists, you couldn't assume that *any* instance variables of a newly initialised object have been zeroed out. What am I missing? ___ 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
Re: leak in AVAudioPlayer ?
Ariel I have seen exactly this problem with the audio data property of AVAudioPlayer - but it only seems to happen in simulator. On the device the data does does get released correctly when the AVAudioPlayer instance is deallocated. I am using ARC. I spent half a day making sure the data was not being retained by some other part of my code. I believe there probably is a bug in the simulator implementation of AVAudioPlayer. I have not checked but guess the same phenomenon is causing the NSURL to be retained. Julian -- Julian Richardson, PhD http://www.ternary.ws On Dec 7, 2012, at 6:23 AM, Ariel Feinerman wrote: > Hi, > > I have seen in leaks profiler the AVAudioPlayer make three retain and only > two release of NSURL > > > -- > best regards > Ariel > ___ > > 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/julian.richardson%40gmail.com > > This email sent to julian.richard...@gmail.com ___ 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
Re: How to implement readonly property
On Dec 7, 2012, at 2:04 PM, Ken Thomases wrote: > On Dec 7, 2012, at 3:08 PM, Greg Parker wrote: >> >> You can't assume that any instance variables of a newly initialized object >> have been zeroed out when >> * you are reading them from threads other than the one that allocated the >> object and >> * there is no synchronization between the allocating thread and the reading >> thread. >> >> In ordinary code there is only one thread involved, or there is already some >> thread synchronization somewhere. >> >> For example, the allocating thread acquires a lock before writing the new >> object's pointer somewhere that the reading thread can see it, and the >> reading thread takes the same lock before reading the object pointer. That >> lock is sufficient synchronization to make it work. >> >> You'll only run into trouble if you are trying to use lock-free >> multiprocessing techniques and you don't use enough memory barriers. > > But this means that dispatch_once() is not uniquely unsafe. It can fail only > in the exact same scenarios where a thread other than the one which allocated > an object might see uninitialized values for generic instance variables. > Such scenarios are, of course, unacceptable and so proper synchronization is > necessary when passing object pointers between threads, full stop. There's > no special care necessary to make dispatch_once() safe, there's just the > ordinary care necessary to make passing of object pointers between threads > "sane". That's right. The problem specific to dispatch_once() is that people sometimes use dispatch_once() in lieu of other synchronization expecting dispatch_once() itself to provide more synchronization than it actually does. > You said that dispatch_once() doesn't promise to provide memory barriers, > but, since the use of GCD hasn't brought catastrophe down on all of our > heads, I assume that dispatch_async() and the like do provide such memory > barriers. Likewise, NSOperationQueue, -performSelector:onThread:..., and the > like must also. Is that right? I would expect that any multiprocessing primitive that does not provide sufficient memory barriers for some uses would document that fact loudly. dispatch_once()'s storage is one documented example of missing barriers. Some of the OSAtomic functions are another example. But pretty much everything heavier-weight than that ought to provide complete memory barriers for any clients. > If you wanted to be paranoid about using an instance variable as a once > predicate, is it sufficient to use OSMemoryBarrier() in the -init method of > the object? Or perhaps there needs to be another call to OSMemoryBarrier() > immediate before the dispatch_once() call, too. Maybe. It depends on the architecture and the precise implementation of dispatch_once(). My guess is that OSMemoryBarrier() in -init is sufficient for dispatch_once(&ivar) on all current OS X and iOS architectures and any other reasonable architectures, and is required on some of them. (As usual, the "unreasonable" architecture is the DEC Alpha, whose memory consistency rules were too loose for mere humans to manage correctly. It looks like everyone learned since then that putting zero data-dependency enforcement in the CPU was a step too far.) -- Greg Parker gpar...@apple.com Runtime Wrangler ___ 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
Re: How to implement readonly property
At 7:56 PM +0700 11/12/12, Gerriet M. Denkmann wrote: - (NSDictionary *)someDictionary; { static NSDictionary *someDictionary; static dispatch_once_t justOnce; dispatch_once( &justOnce, ^ { // create a temp dictionary (might take some time) someDictionary = temp; } ); return someDictionary; } Here's what I usually do: assume that _someDictionary is an instance variable initialized to nil and never changed once initialized to non-nil - (NSDictionary *)someDictionary; { if (!_someDictionary) { @synchronized (self) { if (!_someDictionary) { // create a temp dictionary (might take some time) _someDictionary = temp; } } } return _someDictionary; } the outer if avoids the overhead of @synchronized if _someDictionary is already created -- this is just an optimization the inner if is necessary to resolve the race condition if multiple threads make it past the outer one HTH, -Steve ___ 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
Re: How to implement readonly property
On Dec 7, 2012, at 8:01 PM, Steve Sisak wrote: > Here's what I usually do: > > assume that _someDictionary is an instance variable initialized to nil and > never changed once initialized to non-nil > > - (NSDictionary *)someDictionary; > { > if (!_someDictionary) > { >@synchronized (self) >{ > if (!_someDictionary) > { >// create a temp dictionary (might take some time) > _someDictionary = temp; > } >} > } > > return _someDictionary; > } > > the outer if avoids the overhead of @synchronized if _someDictionary is > already created -- this is just an optimization > > the inner if is necessary to resolve the race condition if multiple threads > make it past the outer one This is a classic anti-pattern called double-checked locking. It is not safe. Don't rely on it. https://en.wikipedia.org/wiki/Double-checked_locking http://erdani.com/publications/DDJ_Jul_Aug_2004_revised.pdf 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
Re: How to implement readonly property
At 8:57 PM -0600 12/7/12, Ken Thomases wrote: > the outer if avoids the overhead of @synchronized if _someDictionary is already created -- this is just an optimization the inner if is necessary to resolve the race condition if multiple threads make it past the outer one This is a classic anti-pattern called double-checked locking. It is not safe. Don't rely on it. https://en.wikipedia.org/wiki/Double-checked_locking http://erdani.com/publications/DDJ_Jul_Aug_2004_revised.pdf Hi Ken, From the first link you cite: The pattern, when implemented in some language/hardware combinations, can be unsafe. At times, it can be considered an anti-pattern.[2] That is far different from being a "a classic anti-pattern". In this example: 1) The language is Obj-C 2) I explicitly used @synchronized(self) and an instance variable So, in this case, what I'm doing is explicitly supported by the language. Your second article is explicitly focused on C++ (and singletons) -- it's also dated 2004. On Mac OS X, the correct implementation of a singleton is dispatch_once() -- in fact, that is the function's raison d'être. So, while I support the position that double-checked locking can be unsafe in con language/hardware combination, in this case we're using language features specifically designed for the purpose. That said, it's worth noting that you need to understand your complier when dealing with synchronization. I'm interested if there are an any issued I'm missing in the Obj-C, @synchronized(self), instance variable case. -Steve ___ 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
Re: How to implement readonly property
On Dec 7, 2012, at 8:18 PM, Steve Sisak wrote: > I'm interested if there are an any issued I'm missing in the Obj-C, > @synchronized(self), instance variable case. Your pattern can fail if this line _someDictionary = temp; isn't atomic. ___ 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
Re: How to implement readonly property
On Dec 7, 2012, at 10:18 PM, Steve Sisak wrote: > At 8:57 PM -0600 12/7/12, Ken Thomases wrote: >> > the outer if avoids the overhead of @synchronized if _someDictionary is >> > already created -- this is just an optimization >>> >>> the inner if is necessary to resolve the race condition if multiple threads >>> make it past the outer one >> >> This is a classic anti-pattern called double-checked locking. It is not >> safe. Don't rely on it. >> https://en.wikipedia.org/wiki/Double-checked_locking >> http://erdani.com/publications/DDJ_Jul_Aug_2004_revised.pdf > > Hi Ken, > > From the first link you cite: > >> The pattern, when implemented in some language/hardware combinations, can be >> unsafe. At times, it can be considered an anti-pattern.[2] > > That is far different from being a "a classic anti-pattern". So Wikipedia waffled. That doesn't make what I said false. Double-checked locking is widely regarded as unsafe in C-based languages. Only in certain languages which have much stronger memory models than C can it be made safe. If in doubt, avoid it. > In this example: > > 1) The language is Obj-C That's part of the problem. Objective-C is a C-based language and doesn't have any stronger guarantees about the memory model than C. If we were working in Java, you might be safe. > 2) I explicitly used @synchronized(self) and an instance variable So? The use of a lock is exactly part of the double-checked _locking_ technique. It doesn't make it safe, it only makes it seem safe. Do you imagine that @synchronized is fundamentally different than any other locking mechanism, such as a pthreads mutex? > So, in this case, what I'm doing is explicitly supported by the language. Nope. The compiler, the CPU, and/or the cache can reorder the execution (or apparent execution) of the instructions within the lock such that the check that's outside of the lock will skip the lock even though the object hasn't been created and fully initialized yet. The problem is precisely that the first check is outside of the lock and outside of any protection provided by memory barriers. > Your second article is explicitly focused on C++ (and singletons) -- it's > also dated 2004. It explains the principles that are applicable to all C-based languages (and even addresses Java). And the fact that it's from 2004 doesn't make it wrong. The passage of time didn't erode its accuracy. It also directly explains that they used the implementation of a singleton as an example but that the problems with double-checked locking are not specific to singletons. > On Mac OS X, the correct implementation of a singleton is dispatch_once() -- > in fact, that is the function's raison d'être. The function's raison d'être is not singletons, it's doing something once and only once. It's also the correct mechanism for what you're using double-checked locking for. > So, while I support the position that double-checked locking can be unsafe in > con language/hardware combination, in this case we're using language features > specifically designed for the purpose. No, you're not. Since you're checking the instance variable outside of the lock, and failing to take the lock based on its state, you are not using the lock in all cases. 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
delaying document close
Dear list, I have a document based app which has a number of per-document background tasks fired off timers. After moving from GC to ARC the app was suffering from crashes when closing documents due to the referencing of deallocated objects. So I've gone through the whole app and implemented -tearDown methods which I then call from my document subclass -windowWillClose:. In many of the -tearDown methods I deactivate the relevant timers by doing, for example, - (void) stopMetadataTimer { if (self.metadataTimer) { [self.aQueue cancelAllOperations]; self.aQueue = nil; [self.metadataTimer invalidate]; self.metadataTimer = nil; } } But I still get occasional crashes so I was wondering if there is a way to delay the closing of the document by one or two seconds to allow all the background processes which may be executing to finish before pulling the rug out from beneath their feet. Best wishes, Martin ___ 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