• 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: NSSound thread-safety?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSSound thread-safety?


  • Subject: Re: NSSound thread-safety?
  • From: Brett Powley <email@hidden>
  • Date: Tue, 17 Jun 2008 10:27:16 +1000

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 (email@hidden)

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:
@process.com.au


This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


References: 
 >NSSound thread-safety? (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: NSSound thread-safety?
  • Next by Date: Re: NSSound thread-safety?
  • Previous by thread: Re: NSSound thread-safety?
  • Next by thread: Re: NSSound thread-safety?
  • Index(es):
    • Date
    • Thread