As far as I'm aware, "not thread safe" means "it's not safe to do this on multiple threads", not "it's not safe to do this on a background thread".

Is there any chance you're trying to play more than one sound at the same time? You don't seem to have any locking there to ensure this.

And:  are you doing anything with  NSSound on the main thread?

Cheers,
Brett




On 17/06/2008, at 10:07 AM, Jens Alfke wrote:

Speaking of AppKit on background threads … I've been using a background thread to load and play NSSounds, because the +soundNamed: and -play methods often block for significant amounts of time (half a second or more), which was stalling other time- critical actions.

This has mostly been working fine, but now I'm occasionally getting crashes. Is NSSound thread-safe? Now that I look, I can't find any documentation; the Cocoa thread safety docs don't refer to NSSound at all.

The crash looks like:

Thread 6 Crashed:
0 com.apple.CoreFoundation 0x9486f1ac CFBundleGetFunctionPointerForName + 32 1 ...ple.CoreServices.CarbonCore 0x9151b2b4 _cf_lookupLibraryEntry(rtFile*, short, RegisteredComponent*) + 244 2 ...ple.CoreServices.CarbonCore 0x9151b2b4 _cf_lookupLibraryEntry(rtFile*, short, RegisteredComponent*) + 244
3   ...ple.CoreServices.CarbonCore      0x914b3fc8 LoadComponent + 248
4   ...ple.CoreServices.CarbonCore      0x914b3d3c OpenAComponent + 256
5   ...ple.CoreServices.CarbonCore      0x914b3c24 OpenComponent + 16
6   com.apple.AppKit                    0x90f143a8 _initializeCA + 796
7 com.apple.AppKit 0x90f13f90 -[NSSound _postInitialization] + 352 8 com.apple.AppKit 0x90f13d50 -[NSSound initWithContentsOfURL:byReference:] + 256 9 com.apple.AppKit 0x91226070 +[NSSound _searchForSoundNamed:] + 512 10 com.apple.AppKit 0x9122618c +[NSSound soundNamed:] + 212 11 com.mooseyard.Cloudy 0x00003b54 -[MyClass _bg_playSoundNamed:] + 356 12 com.apple.Foundation 0x95b5fdec __NSThread__main__ + 1004
13  libSystem.B.dylib                   0x95e39658 _pthread_start + 316

All I'm doing is using a -performSelectorOnBackgroundThread: to call the following:

- (void) _bg_playSoundNamed: (NSString*)name
{
   NSAutoreleasePool *pool = [NSAutoreleasePool new];
       NSSound *sound = [NSSound soundNamed: name];
       if(sound) {
           sound.volume = _volume;
           [sound play];
       } else
            Warn(@"Couldn't load sound named '%@'",name);
   [pool drain];
}

—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:
http://lists.apple.com/mailman/options/cocoa-dev/brett %40process.com.au

This email sent to [EMAIL PROTECTED]

_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to