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

NSSound thread-safety?


  • Subject: NSSound thread-safety?
  • From: Jens Alfke <email@hidden>
  • Date: Mon, 16 Jun 2008 17:07:11 -0700

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

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

  • Follow-Ups:
    • Re: NSSound thread-safety?
      • From: Ricky Sharp <email@hidden>
    • Re: NSSound thread-safety?
      • From: Brett Powley <email@hidden>
    • Re: NSSound thread-safety?
      • From: j o a r <email@hidden>
  • Prev by Date: Newbie interface questions - multiple "modal" windows
  • Next by Date: Re: NSSound thread-safety?
  • Previous by thread: Re: Newbie interface questions - multiple "modal" windows
  • Next by thread: Re: NSSound thread-safety?
  • Index(es):
    • Date
    • Thread